Package org.greenrobot.essentials.io
Class IoUtils
- java.lang.Object
-
- org.greenrobot.essentials.io.IoUtils
-
public class IoUtils extends java.lang.ObjectUtils for dealing with IO (streams, readers, ...).
-
-
Field Summary
Fields Modifier and Type Field Description private static intBUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description IoUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcopyAllBytes(java.io.InputStream in, java.io.OutputStream out)Copies all available data from in to out without closing any stream.static byte[]getDigest(java.io.InputStream in, java.lang.String digestAlgo)static java.lang.StringgetMd5(java.io.InputStream in)static java.lang.StringgetSha1(java.io.InputStream in)static java.lang.StringgetSha256(java.io.InputStream in)static byte[]readAllBytes(java.io.InputStream in)static byte[]readAllBytesAndClose(java.io.InputStream in)static java.lang.StringreadAllChars(java.io.Reader reader)static java.lang.StringreadAllCharsAndClose(java.io.Reader reader)static voidsafeClose(java.io.Closeable closeable)Closes the given resource (e.g.static voidupdateChecksum(java.io.InputStream in, java.util.zip.Checksum checksum)static voidwriteAllCharsAndClose(java.io.Writer writer, java.lang.CharSequence text)
-
-
-
Field Detail
-
BUFFER_SIZE
private static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
readAllBytes
public static byte[] readAllBytes(java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
readAllBytesAndClose
public static byte[] readAllBytesAndClose(java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
readAllChars
public static java.lang.String readAllChars(java.io.Reader reader) throws java.io.IOException- Throws:
java.io.IOException
-
readAllCharsAndClose
public static java.lang.String readAllCharsAndClose(java.io.Reader reader) throws java.io.IOException- Throws:
java.io.IOException
-
writeAllCharsAndClose
public static void writeAllCharsAndClose(java.io.Writer writer, java.lang.CharSequence text) throws java.io.IOException- Throws:
java.io.IOException
-
updateChecksum
public static void updateChecksum(java.io.InputStream in, java.util.zip.Checksum checksum) throws java.io.IOException- Throws:
java.io.IOException
-
getMd5
public static java.lang.String getMd5(java.io.InputStream in) throws java.io.IOException- Returns:
- MD5 digest (32 hex characters).
- Throws:
java.io.IOException
-
getSha1
public static java.lang.String getSha1(java.io.InputStream in) throws java.io.IOException- Returns:
- SHA-1 digest (40 hex characters).
- Throws:
java.io.IOException
-
getSha256
public static java.lang.String getSha256(java.io.InputStream in) throws java.io.IOException- Returns:
- SHA-256 digest (64 hex characters).
- Throws:
java.io.IOException
-
getDigest
public static byte[] getDigest(java.io.InputStream in, java.lang.String digestAlgo) throws java.io.IOException- Throws:
java.io.IOException
-
copyAllBytes
public static int copyAllBytes(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOExceptionCopies all available data from in to out without closing any stream.- Returns:
- number of bytes copied
- Throws:
java.io.IOException
-
safeClose
public static void safeClose(java.io.Closeable closeable)
Closes the given resource (e.g. stream, reader, writer, etc.) inside a try/catch. Does nothing if stream is null.
-
-