Package com.oracle.bmc.util
Class StreamUtils
- java.lang.Object
- 
- com.oracle.bmc.util.StreamUtils
 
- 
 public class StreamUtils extends Object Utility methods to work with streams.
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseQuietly(InputStream stream)Close a stream without raising an exception.static Optional<String>contentDiffers(InputStream input1, InputStream input2)ReturnOptional.empty()if the content of the two input streams is the same.static ByteArrayInputStreamcreateByteArrayInputStream(byte[] buffer)Creates a newByteArrayInputStream.static StringgetStreamWarningMessage(String clientName, String operationNames)Gets the stream warning message to warn the users about closing the streamstatic booleanisExtraStreamLogsEnabled()The boolean value indicating if extra logs related to operations that return streams are enabled/disabled.static InputStreamlimitRemainingStreamLength(InputStream is, long limit)Limit the number of bytes remaining in the input stream to at most this many bytes.static longskipBytesInStream(InputStream is, long count)Skip the specified number of bytes in the stream.static byte[]toByteArray(InputStream inputStream)Convert the input stream to a byte array.static InputStreamtoInputStream(File file)Convert a File to an InputStream.static StringtoString(InputStream is, Charset charset)Convert the input stream to a string.
 
- 
- 
- 
Method Detail- 
isExtraStreamLogsEnabledpublic 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. 
 - 
closeQuietlypublic static void closeQuietly(InputStream stream) Close a stream without raising an exception.- Parameters:
- stream- The stream to close.
 
 - 
toInputStreampublic static InputStream toInputStream(File file) Convert a File to an InputStream.This uses WrappedFileInputStreamso the caller still has access to the original file if needed. If the file is not valid, an IllegalArgumentException will be raised.- Parameters:
- file- The file to convert to a stream.
- Returns:
- A new InputStream instance.
 
 - 
createByteArrayInputStreampublic static ByteArrayInputStream createByteArrayInputStream(byte[] buffer) Creates a newByteArrayInputStream.This uses WrappedByteArrayInputStreamso the underlying buffer can be reused by multiple copies of the stream if needed.- Parameters:
- buffer- The byte buffer.
- Returns:
- A new ByteArrayInputStream instance.
 
 - 
toStringpublic static String toString(InputStream is, Charset charset) Convert the input stream to a string.- Parameters:
- is- input stream
- charset- charset to use
- Returns:
- string
 
 - 
toByteArraypublic static byte[] toByteArray(InputStream inputStream) throws IOException Convert the input stream to a byte array.- Parameters:
- inputStream- input stream
- Returns:
- byte array
- Throws:
- IOException
 
 - 
contentDifferspublic static Optional<String> contentDiffers(InputStream input1, InputStream input2) throws IOException ReturnOptional.empty()if the content of the two input streams is the same.Otherwise, it returns a description of the first difference. - Parameters:
- input1- first input stream
- input2- second input stream
- Returns:
- description of the first difference, or Optional.empty()if the contents are the same
- Throws:
- IOException
 
 - 
skipBytesInStreampublic static long skipBytesInStream(InputStream is, long count) throws IOException Skip the specified number of bytes in the stream.- Parameters:
- is- stream
- count- number of bytes to skip
- Returns:
- number of bytes that were skipped
- Throws:
- IOException
 
 - 
limitRemainingStreamLengthpublic 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- input stream
- limit- upper limit of remaining bytes
- Returns:
- limited stream
 
 
- 
 
-