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 com.google.common.annotations.J2ktIncompatible;
019import java.io.DataOutput;
020import java.io.IOException;
021
022/**
023 * An extension of {@code DataOutput} for writing to in-memory byte arrays; its methods offer
024 * identical functionality but do not throw {@link IOException}.
025 *
026 * <p>To create an instance, use {@link ByteStreams#newDataOutput()} or the other overload of that
027 * method.
028 *
029 * @author Jayaprabhakar Kadarkarai
030 * @since 1.0
031 */
032@J2ktIncompatible
033@GwtIncompatible
034public interface ByteArrayDataOutput extends DataOutput {
035  @Override
036  void write(int b);
037
038  @Override
039  void write(byte[] b);
040
041  @Override
042  void write(byte[] b, int off, int len);
043
044  @Override
045  void writeBoolean(boolean v);
046
047  @Override
048  void writeByte(int v);
049
050  @Override
051  void writeShort(int v);
052
053  @Override
054  void writeChar(int v);
055
056  @Override
057  void writeInt(int v);
058
059  @Override
060  void writeLong(long v);
061
062  @Override
063  void writeFloat(float v);
064
065  @Override
066  void writeDouble(double v);
067
068  @Override
069  void writeChars(String s);
070
071  @Override
072  void writeUTF(String s);
073
074  /**
075   * @deprecated This method is dangerous as it discards the high byte of every character. For
076   *     UTF-8, use {@code write(s.getBytes(StandardCharsets.UTF_8))}.
077   */
078  @Deprecated
079  @Override
080  void writeBytes(String s);
081
082  /** Returns the contents that have been written to this instance, as a byte array. */
083  byte[] toByteArray();
084}