public abstract class IoUtil extends Object
Modifier and Type | Field and Description |
---|---|
static List<Encoding> |
SUPPORTED_COMPRESSION_ENCODINGS
Constant.
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
compress(CharSequence text,
Encoding encoding,
String documentName)
Compresses text into a byte array.
|
static byte[] |
compress(InputStream in,
Encoding encoding,
String documentName)
Compresses an input stream into a byte array, without the initial two
|
static void |
copyStream(InputStream in,
OutputStream out)
Copies streams.
|
static String |
decodeUtf8(byte[] bytes)
Safely decodes a UTF-8-encoded string.
|
static Object |
deserialize(byte[] bytes)
Deserializes an object.
|
static byte[] |
encodeUtf8(String string)
Safely decodes a string as UTF-8.
|
static File |
getUniqueFile(File file)
Makes sure a file instance is unique to this VM for its absolute path.
|
static Properties |
loadProperties(File file)
Loads properties from a file if it exists.
|
static String |
readUtf8(DataInput in)
Safely reads a string as UTF-8 from a byte stream.
|
static void |
saveProperties(Properties properties,
File file)
Saves properties to a file.
|
static byte[] |
serialize(Object o)
Serializes an object.
|
static void |
unzip(File file,
File directory)
Unpacks a zip file into a directory.
|
static void |
writeUtf8(DataOutput out,
String string)
Safely writes a string in UTF-8 to a byte stream.
|
static void |
zip(File directory,
File file)
Recursively packs a directory into a zip file.
|
public static void copyStream(InputStream in, OutputStream out) throws IOException
in
- Input streamout
- Output streamIOException
- In case of a reading or writing errorpublic static Properties loadProperties(File file) throws IOException
file
- The fileIOException
- In case of a reading errorpublic static void saveProperties(Properties properties, File file) throws IOException
properties
- The propertiesfile
- The fileIOException
- In case of a writing errorpublic static File getUniqueFile(File file)
file
- The file instancepublic static byte[] compress(InputStream in, Encoding encoding, String documentName) throws IOException
in
- The input streamencoding
- The encodingdocumentName
- The document name (only used with Encoding.ZIP
)IOException
- In case of a reading or compression errorpublic static byte[] compress(CharSequence text, Encoding encoding, String documentName) throws IOException
text
- The stringencoding
- The encodingdocumentName
- The document name (only used with Encoding.ZIP
)IOException
- In case of a compression errorpublic static final void zip(File directory, File file) throws IOException
directory
- The directory to zipfile
- The zip fileIOException
- In case of a reading, writing or compression errorpublic static void unzip(File file, File directory) throws IOException
file
- The zip filedirectory
- The directoryIOException
- In case of a reading, writing or decompression errorpublic static byte[] serialize(Object o) throws IOException
o
- The object or nullIOException
- In case of a writing or serialization errorpublic static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException
bytes
- The bytes or nullIOException
- In case of a reading or deserialization errorClassNotFoundException
- In case an unknown class has been serializedpublic static String decodeUtf8(byte[] bytes)
bytes
- The bytespublic static byte[] encodeUtf8(String string)
string
- The stringpublic static String readUtf8(DataInput in) throws IOException
Unlike DataInput.readUTF()
, this implementation does not limit
the string size.
in
- The streamIOException
- In case of a reading or decoding errorwriteUtf8(DataOutput, String)
,
decodeUtf8(byte[])
public static void writeUtf8(DataOutput out, String string) throws IOException
Unlike DataOutput.writeUTF(String)
, this implementation does not
limit the string size.
out
- The streamstring
- The string or nullIOException
- In case of a writing or encoding errorreadUtf8(DataInput)
,
encodeUtf8(String)
Copyright © 2009-2016 Three Crickets LLC.