Top Description Fields Constructors Methods
com.oracle.bmc.util

public Class StreamUtils

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .BufferedOutputStream, .BufferedReader, .ByteArrayInputStream, .ByteArrayOutputStream, .File, .IOException, .InputStream, .InputStreamReader, .Reader, com.oracle.bmc.io.internal.WrappedByteArrayInputStream, .WrappedFileInputStream, com.oracle.bmc.util.internal.StringUtils, .Validate, org.slf4j.Logger, java.nio.charset.Charset, java.util.Optional

Utility methods to work with streams.

Field Summary

Modifier and TypeField and Description
private static final boolean
private static final Logger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
closeQuietly(InputStream
The stream to close.
stream
)

Close a stream without raising an exception.

public static Optional<String>

Returns:

description of the first difference, or Optional#empty() if the contents are the same
contentDiffers
(InputStream
first input stream
input1
,
InputStream
second input stream
input2
)

Return Optional#empty() if the content of the two input streams is the same.

public static ByteArrayInputStream

Returns:

A new ByteArrayInputStream instance.
createByteArrayInputStream
(byte[]
The byte buffer.
buffer
)

Creates a new ByteArrayInputStream.

public static String
getStreamWarningMessage(String clientName, String operationNames)

Gets the stream warning message to warn the users about closing the stream

public static boolean
isExtraStreamLogsEnabled()

The boolean value indicating if extra logs related to operations that return streams are enabled/disabled.

private static boolean
public static InputStream

Returns:

limited stream
limitRemainingStreamLength
(InputStream
input stream
is
,
long
upper limit of remaining bytes
limit
)

Limit the number of bytes remaining in the input stream to at most this many bytes.

public static long

Returns:

number of bytes that were skipped
skipBytesInStream
(InputStream
stream
is
,
long
number of bytes to skip
count
)

Skip the specified number of bytes in the stream.

public static byte[]

Returns:

byte array
toByteArray
(InputStream
input stream
inputStream
)

Convert the input stream to a byte array.

public static InputStream

Returns:

A new InputStream instance.
toInputStream
(File
The file to convert to a stream.
file
)

Convert a File to an InputStream.

public static String

Returns:

string
toString
(InputStream
input stream
is
,
Charset
charset to use
charset
)

Convert the input stream to a string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

isExtraStreamLogsEnabledback to summary
private static final boolean isExtraStreamLogsEnabled
LOGback to summary
private static final Logger LOG

Constructor Detail

StreamUtilsback to summary
private StreamUtils()

Method Detail

closeQuietlyback to summary
public static void closeQuietly(InputStream stream)

Close a stream without raising an exception.

Parameters
stream:InputStream

The stream to close.

contentDiffersback to summary
public static Optional<String> contentDiffers(InputStream input1, InputStream input2) throws IOException

Return Optional#empty() if the content of the two input streams is the same. Otherwise, it returns a description of the first difference.

Parameters
input1:InputStream

first input stream

input2:InputStream

second input stream

Returns:Optional<String>

description of the first difference, or Optional#empty() if the contents are the same

createByteArrayInputStreamback to summary
public static ByteArrayInputStream createByteArrayInputStream(byte[] buffer)

Creates a new ByteArrayInputStream. This uses WrappedByteArrayInputStream so the underlying buffer can be reused by multiple copies of the stream if needed.

Parameters
buffer:byte[]

The byte buffer.

Returns:ByteArrayInputStream

A new ByteArrayInputStream instance.

getStreamWarningMessageback to summary
public static String getStreamWarningMessage(String clientName, String operationNames)

Gets the stream warning message to warn the users about closing the stream

isExtraStreamLogsEnabledback to summary
public static boolean isExtraStreamLogsEnabled()

The boolean value indicating if extra logs related to operations that return streams are enabled/disabled. Disabling this will disable warnings to close the streams, logs about wrapping response stream in an auto-closeble stream. Default is true.

isExtraStreamLogsEnabledViaSystemPropertyback to summary
private static boolean isExtraStreamLogsEnabledViaSystemProperty()
limitRemainingStreamLengthback to summary
public static InputStream limitRemainingStreamLength(InputStream is, long limit)

Limit the number of bytes remaining in the input stream to at most this many bytes. The input stream may reach its end earlier.

Parameters
is:InputStream

input stream

limit:long

upper limit of remaining bytes

Returns:InputStream

limited stream

skipBytesInStreamback to summary
public static long skipBytesInStream(InputStream is, long count) throws IOException

Skip the specified number of bytes in the stream.

Parameters
is:InputStream

stream

count:long

number of bytes to skip

Returns:long

number of bytes that were skipped

toByteArrayback to summary
public static byte[] toByteArray(InputStream inputStream) throws IOException

Convert the input stream to a byte array.

Parameters
inputStream:InputStream

input stream

Returns:byte[]

byte array

toInputStreamback to summary
public static InputStream toInputStream(File file)

Convert a File to an InputStream. This uses WrappedFileInputStream so the caller still has access to the original file if needed. If the file is not valid, an IllegalArgumentException will be raised.

Parameters
file:File

The file to convert to a stream.

Returns:InputStream

A new InputStream instance.

toStringback to summary
public static String toString(InputStream is, Charset charset)

Convert the input stream to a string.

Parameters
is:InputStream

input stream

charset:Charset

charset to use

Returns:String

string