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