001    /*
002     * Copyright (C) 2009 The Guava Authors
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package com.google.common.io;
018    
019    import java.io.DataOutput;
020    import java.io.IOException;
021    
022    /**
023     * An extension of {@code DataOutput} for writing to in-memory byte arrays; its
024     * methods offer identical functionality but do not throw {@link IOException}.
025     *
026     * @author Jayaprabhakar Kadarkarai
027     * @since 1.0
028     */
029    public interface ByteArrayDataOutput extends DataOutput {
030      @Override void write(int b);
031      @Override void write(byte b[]);
032      @Override void write(byte b[], int off, int len);
033      @Override void writeBoolean(boolean v);
034      @Override void writeByte(int v);
035      @Override void writeShort(int v);
036      @Override void writeChar(int v);
037      @Override void writeInt(int v);
038      @Override void writeLong(long v);
039      @Override void writeFloat(float v);
040      @Override void writeDouble(double v);
041      @Override void writeChars(String s);
042      @Override void writeUTF(String s);
043    
044      /**
045       * @deprecated This method is dangerous as it discards the high byte of
046       * every character. For UTF-8, use {@code write(s.getBytes(Charsets.UTF_8))}.
047       */
048      @Deprecated @Override void writeBytes(String s);
049    
050      /**
051       * Returns the contents that have been written to this instance,
052       * as a byte array.
053       */
054      byte[] toByteArray();
055    }