public class

StreamUtil

extends Object
java.lang.Object
   ↳ com.facebook.common.util.StreamUtil

Class Overview

Utility method for dealing with Streams.

Summary

Public Constructors
StreamUtil()
Public Methods
static byte[] getBytesFromStream(InputStream inputStream, int hint)
Efficiently fetch the bytes from the InputStream, provided that caller can guess exact numbers of bytes that can be read from inputStream.
static byte[] getBytesFromStream(InputStream is)
Efficiently fetch bytes from InputStream is by delegating to getBytesFromStream(is, is.available())
static long skip(InputStream inputStream, long bytesCount)
Skips exactly bytesCount bytes in inputStream unless end of stream is reached first.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public StreamUtil ()

Public Methods

public static byte[] getBytesFromStream (InputStream inputStream, int hint)

Efficiently fetch the bytes from the InputStream, provided that caller can guess exact numbers of bytes that can be read from inputStream. Avoids one extra byte[] allocation that ByteStreams.toByteArray() performs.

Parameters
hint - size of inputStream's content in bytes
Throws
IOException

public static byte[] getBytesFromStream (InputStream is)

Efficiently fetch bytes from InputStream is by delegating to getBytesFromStream(is, is.available())

Throws
IOException

public static long skip (InputStream inputStream, long bytesCount)

Skips exactly bytesCount bytes in inputStream unless end of stream is reached first.

Parameters
inputStream input stream to skip bytes from
bytesCount number of bytes to skip
Returns
  • number of skipped bytes
Throws
IOException