Home | History | Annotate | Download | only in okio
      1 /*
      2  * Copyright (C) 2014 Square, Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package okio;
     17 
     18 import java.io.IOException;
     19 import java.io.OutputStream;
     20 
     21 /**
     22  * A sink that keeps a buffer internally so that callers can do small writes
     23  * without a performance penalty.
     24  */
     25 public interface BufferedSink extends Sink {
     26   /** Returns this sink's internal buffer. */
     27   OkBuffer buffer();
     28 
     29   BufferedSink write(ByteString byteString) throws IOException;
     30 
     31   /**
     32    * Like {@link OutputStream#write}, this writes a complete byte array to this
     33    * sink.
     34    */
     35   BufferedSink write(byte[] source) throws IOException;
     36 
     37   /**
     38    * Like {@link OutputStream#write}, this writes {@code byteCount} bytes
     39    * of {@code source}, starting at {@code offset}.
     40    */
     41   BufferedSink write(byte[] source, int offset, int byteCount) throws IOException;
     42 
     43   /** Encodes {@code string} in UTF-8 and writes it to this sink. */
     44   BufferedSink writeUtf8(String string) throws IOException;
     45 
     46   /** Writes a byte to this sink. */
     47   BufferedSink writeByte(int b) throws IOException;
     48 
     49   /** Writes a big-endian short to this sink using two bytes. */
     50   BufferedSink writeShort(int s) throws IOException;
     51 
     52   /** Writes a little-endian short to this sink using two bytes. */
     53   BufferedSink writeShortLe(int s) throws IOException;
     54 
     55   /** Writes a big-endian int to this sink using four bytes. */
     56   BufferedSink writeInt(int i) throws IOException;
     57 
     58   /** Writes a little-endian int to this sink using four bytes. */
     59   BufferedSink writeIntLe(int i) throws IOException;
     60 
     61   /** Writes a big-endian long to this sink using eight bytes. */
     62   BufferedSink writeLong(long v) throws IOException;
     63 
     64   /** Writes a little-endian long to this sink using eight bytes. */
     65   BufferedSink writeLongLe(long v) throws IOException;
     66 
     67   /** Writes complete segments to this sink. Like {@link #flush}, but weaker. */
     68   BufferedSink emitCompleteSegments() throws IOException;
     69 
     70   /** Returns an output stream that writes to this sink. */
     71   OutputStream outputStream();
     72 }
     73