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 * @author Jayaprabhakar Kadarkarai
027 * @since 1.0
028 */
029@J2ktIncompatible
030@GwtIncompatible
031@ElementTypesAreNonnullByDefault
032public interface ByteArrayDataOutput extends DataOutput {
033  @Override
034  void write(int b);
035
036  @Override
037  void write(byte b[]);
038
039  @Override
040  void write(byte b[], int off, int len);
041
042  @Override
043  void writeBoolean(boolean v);
044
045  @Override
046  void writeByte(int v);
047
048  @Override
049  void writeShort(int v);
050
051  @Override
052  void writeChar(int v);
053
054  @Override
055  void writeInt(int v);
056
057  @Override
058  void writeLong(long v);
059
060  @Override
061  void writeFloat(float v);
062
063  @Override
064  void writeDouble(double v);
065
066  @Override
067  void writeChars(String s);
068
069  @Override
070  void writeUTF(String s);
071
072  /**
073   * @deprecated This method is dangerous as it discards the high byte of every character. For
074   *     UTF-8, use {@code write(s.getBytes(StandardCharsets.UTF_8))}.
075   */
076  @Deprecated
077  @Override
078  void writeBytes(String s);
079
080  /** Returns the contents that have been written to this instance, as a byte array. */
081  byte[] toByteArray();
082}