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