public final class UtilIO
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
BUFFER_SIZE
Buffer size
|
static java.lang.String |
CURRENT_DIRECTORY
Path that represents the current directory
|
static int |
HEADER_SIZE
Size of a file header
|
static int |
KILO_BYTES
One kilo-byte in bytes
|
static int |
MEGA_BYTES
One mega-byte in bytes
|
private static java.io.File |
outsideDirectory
Directory external of the code
|
static char |
PATH_SEPARATOR
Path separator used in URL, ZIP, JAR
|
static java.lang.String |
PREVIOUS_DIRECTORY
Path the represents the parent directory
|
private static java.io.File |
temporaryDirectory
Temporary directory
|
Modifier | Constructor and Description |
---|---|
private |
UtilIO()
To avoid instance
|
Modifier and Type | Method and Description |
---|---|
static double |
byteArrayToDouble(byte[] array)
Create a double from a byte array.
|
static long |
byteArrayToLong(byte[] array)
Create a long from a byte array.
|
static java.math.BigInteger |
computeBigIntegerSHA(java.io.InputStream inputStream)
Compute the SHA code of a stream
|
static byte[] |
computeByteArraySHA(java.io.InputStream inputStream)
Compute SHA for a stream
|
static java.lang.String |
computeMD5_SHA_ID(java.io.File file)
Compute MD5 and SHA for a file, can be us as unique ID
|
static java.lang.String |
computeMD5_SHA_ID(java.io.InputStream inputStream)
Compute MD5 and SHA for a stream, can be us as unique ID
|
static java.lang.String |
computeMD5(java.awt.image.BufferedImage bufferedImage)
Compute MD5 of an image
|
static java.lang.String |
computeMD5(java.io.File file)
Compute MD5 of a file
|
static java.lang.String |
computeMD5(java.io.InputStream inputStream)
Compute MD5 for a stream
|
static java.lang.String |
computeMD5(int[] data)
Compute MD5 for an array of integer
|
static java.lang.String |
computeRelativePath(java.io.File start,
java.io.File destination)
Compute relative path for go from a file to an other
|
static java.lang.String |
computeSHA(java.io.File file)
Compute SHA for a file
|
static java.lang.String |
computeSHA(java.io.InputStream inputStream)
Compute SHA for a stream
|
static void |
copy(java.io.File source,
java.io.File destination)
Copy a file or directory.
|
static boolean |
createDirectory(java.io.File directory)
Create a directory and its parents if needs
|
static boolean |
createFile(java.io.File file)
Create a file and its parent directory if need
|
static java.io.File |
createTemporaryFile(java.lang.String string)
Create a temporary file.
|
static boolean |
delete(java.io.File file)
Delete a file or a directory.
|
static byte[] |
doubleToByteArray(double d)
Create a byte array from double.
|
static boolean |
isVirtualLink(java.io.File file)
Indicates if a file is a virtual link.
|
static byte[] |
longToByteArray(long l)
Create a byte array from long.
|
static java.io.File |
obtainExternalFile(java.lang.String path)
Obtain a file outside of the code.
|
static java.io.File |
obtainFile(java.io.File directory,
java.lang.String path)
Obtain a file relative to a directory
|
static java.io.File |
obtainFile(java.io.File directory,
java.lang.String path,
char separator)
Obtain a file relative to a directory
|
static java.io.File |
obtainOutsideDirectory()
Obtain directory outside the code
|
static java.io.File |
obtainTemporaryDirectory()
Temporary directory
|
static java.math.BigInteger |
readBigInteger(java.io.InputStream inputStream)
Read a
BigInteger from a stream. |
static <B extends Binarizable> |
readBinarizable(java.lang.Class<B> clas,
java.io.InputStream inputStream)
Read a
Binarizable inside a stream. |
static <B extends Binarizable> |
readBinarizableNamed(java.io.InputStream inputStream)
Read a
Binarizable inside a stream. |
static byte[] |
readByteArray(java.io.InputStream inputStream)
Read a byte array from stream
|
static double |
readDouble(java.io.InputStream inputStream)
Read double from stream
|
static byte[] |
readFileHeader(java.io.File file)
Read a file header (First bytes of a file)
|
static int |
readInteger(java.io.InputStream inputStream)
Read an integer from stream
|
static long |
readLong(java.io.InputStream inputStream)
Read long from stream
|
static int |
readStream(java.io.InputStream inputStream,
byte[] array)
Read stream and fill an array.
|
static int |
readStream(java.io.InputStream inputStream,
byte[] array,
int offset)
Read stream and fill an array.
|
static int |
readStream(java.io.InputStream inputStream,
byte[] array,
int offset,
int length)
Read stream and fill an array.
|
static java.lang.String |
readString(java.io.InputStream inputStream)
Read stream from stream
|
static void |
rename(java.io.File source,
java.io.File destination)
Rename a file
|
static void |
unzip(java.io.File directoryDestination,
java.io.File zip)
Unzip a file inside a directory
|
static void |
unzip(java.io.File directoryDestination,
java.io.InputStream inputStreamZip)
Unzip a stream inside a directory
|
static void |
write(java.io.File fileSource,
java.io.File fileDestination)
Copy a file inside an other one
|
static void |
write(java.io.File fileSource,
java.io.OutputStream outputStream)
Write a file inside a stream
|
static void |
write(java.io.InputStream inputStream,
java.io.File fileDestination)
Write a stream inside a file
|
static void |
write(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
Write a stream inside on other one
|
static void |
writeBigInteger(java.math.BigInteger bigInteger,
java.io.OutputStream outputStream)
Write a
BigInteger in stream. |
static void |
writeBinarizable(Binarizable binarizable,
java.io.OutputStream outputStream)
Write a
Binarizable inside a stream. |
static void |
writeBinarizableNamed(Binarizable binarizable,
java.io.OutputStream outputStream)
Write a
Binarizable inside a stream. |
static void |
writeByteArray(byte[] array,
int offset,
int length,
java.io.OutputStream outputStream)
Write a part of byte array on stream
|
static void |
writeByteArray(byte[] array,
java.io.OutputStream outputStream)
Write an array on stream.
|
static void |
writeDouble(double d,
java.io.OutputStream outputStream)
Write double in a stream
|
static void |
writeInteger(int integer,
java.io.OutputStream outputStream)
Write an integer to stream
|
static void |
writeLong(long integer,
java.io.OutputStream outputStream)
Write long in a stream
|
static void |
writeString(java.lang.String string,
java.io.OutputStream outputStream)
Write string to stream
|
static void |
zip(java.io.File source,
java.io.File destination)
Zip a file or directory inside a file
|
static void |
zip(java.io.File source,
java.io.OutputStream outputStreamZip)
Zip a file or directory inside a stream
|
private static java.io.File outsideDirectory
private static java.io.File temporaryDirectory
public static final int BUFFER_SIZE
public static final java.lang.String CURRENT_DIRECTORY
public static final int HEADER_SIZE
public static final int KILO_BYTES
public static final int MEGA_BYTES
public static final char PATH_SEPARATOR
public static final java.lang.String PREVIOUS_DIRECTORY
public static double byteArrayToDouble(byte[] array)
doubleToByteArray(double)
array
- Array to convertpublic static long byteArrayToLong(byte[] array)
longToByteArray(long)
array
- Array to convertpublic static java.math.BigInteger computeBigIntegerSHA(java.io.InputStream inputStream) throws java.security.NoSuchAlgorithmException, java.io.IOException
inputStream
- Stream to readjava.security.NoSuchAlgorithmException
- If SHA not implemented (Should never append, its java base algorithm)java.io.IOException
- On reading issuepublic static byte[] computeByteArraySHA(java.io.InputStream inputStream) throws java.security.NoSuchAlgorithmException, java.io.IOException
inputStream
- Stream to readjava.security.NoSuchAlgorithmException
- If system not support SHAjava.io.IOException
- On reading stream issuepublic static java.lang.String computeMD5(java.awt.image.BufferedImage bufferedImage) throws java.security.NoSuchAlgorithmException, java.io.IOException
bufferedImage
- Image to compute it's MD5java.security.NoSuchAlgorithmException
- If system not support MD5java.io.IOException
- On reading image issuepublic static java.lang.String computeMD5(java.io.File file) throws java.security.NoSuchAlgorithmException, java.io.IOException
file
- File to compute its MD5java.security.NoSuchAlgorithmException
- If system not support MD5java.io.IOException
- On reading file issuepublic static java.lang.String computeMD5(java.io.InputStream inputStream) throws java.security.NoSuchAlgorithmException, java.io.IOException
inputStream
- Stream to readjava.security.NoSuchAlgorithmException
- If system not support MD5java.io.IOException
- On reading stream issuepublic static java.lang.String computeMD5(int[] data) throws java.security.NoSuchAlgorithmException, java.io.IOException
data
- Array to compute its MD5java.security.NoSuchAlgorithmException
- If system not support MD5java.io.IOException
- On reading array issuepublic static java.lang.String computeMD5_SHA_ID(java.io.File file) throws java.security.NoSuchAlgorithmException, java.io.IOException
file
- File to readjava.security.NoSuchAlgorithmException
- If system not support MD5 or SHAjava.io.IOException
- On reading stream issuepublic static java.lang.String computeMD5_SHA_ID(java.io.InputStream inputStream) throws java.security.NoSuchAlgorithmException, java.io.IOException
inputStream
- Stream to readjava.security.NoSuchAlgorithmException
- If system not support MD5 or SHAjava.io.IOException
- On reading stream issuepublic static java.lang.String computeRelativePath(java.io.File start, java.io.File destination)
start
- Start filedestination
- Destination filepublic static java.lang.String computeSHA(java.io.File file) throws java.security.NoSuchAlgorithmException, java.io.IOException
file
- File to readjava.security.NoSuchAlgorithmException
- If system not support SHAjava.io.IOException
- On reading stream issuepublic static java.lang.String computeSHA(java.io.InputStream inputStream) throws java.security.NoSuchAlgorithmException, java.io.IOException
inputStream
- Stream to readjava.security.NoSuchAlgorithmException
- If system not support SHAjava.io.IOException
- On reading stream issuepublic static void copy(java.io.File source, java.io.File destination) throws java.io.IOException
source
- File or directory sourcedestination
- File or directory destinationjava.io.IOException
- On coping issuepublic static boolean createDirectory(java.io.File directory)
directory
- Directory to createtrue
if creation succeed. false
if failedpublic static boolean createFile(java.io.File file)
file
- File to createtrue
if creation succeed. false
if failedpublic static java.io.File createTemporaryFile(java.lang.String string) throws java.io.IOException
string
- File namejava.io.IOException
- On creation issuepublic static boolean delete(java.io.File file)
file
- File/directory to deletetrue
if succeed. false
if failed, may be some deletion have happenpublic static byte[] doubleToByteArray(double d)
byteArrayToDouble(byte[])
d
- Double to convertpublic static boolean isVirtualLink(java.io.File file)
file
- File to testtrue
if it is a virtual linkpublic static byte[] longToByteArray(long l)
byteArrayToLong(byte[])
l
- Long to convertpublic static java.io.File obtainExternalFile(java.lang.String path)
path
- Relative pathpublic static java.io.File obtainFile(java.io.File directory, java.lang.String path)
directory
- Directory referencepath
- Path searchpublic static java.io.File obtainFile(java.io.File directory, java.lang.String path, char separator)
directory
- Directory referencepath
- Path searchseparator
- Separator use inside the pathpublic static java.io.File obtainOutsideDirectory()
public static java.io.File obtainTemporaryDirectory()
public static java.math.BigInteger readBigInteger(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- Stream to readBigInteger
readjava.io.IOException
- On reading issuepublic static <B extends Binarizable> B readBinarizable(java.lang.Class<B> clas, java.io.InputStream inputStream) throws java.io.IOException
Binarizable
inside a stream.Binarizable
should be previously written by writeBinarizable(Binarizable, OutputStream)
B
- Binarizable
typeclas
- Class of the Binarizable
inputStream
- Stream to readBinarizable
readjava.io.IOException
- On read the stream or the data not represents the asked Binarizable
public static <B extends Binarizable> B readBinarizableNamed(java.io.InputStream inputStream) throws java.io.IOException
Binarizable
inside a stream.Binarizable
should be previously written by writeBinarizableNamed(Binarizable, OutputStream)
B
- Binarizable
typeinputStream
- Stream to readBinarizable
readjava.io.IOException
- On read the stream or the data not represents the asked Binarizable
public static byte[] readByteArray(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- Stream to readjava.io.IOException
- On reading issuepublic static double readDouble(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- Stream to readjava.io.IOException
- On reading problempublic static byte[] readFileHeader(java.io.File file) throws java.io.IOException
file
- File to read headerjava.io.IOException
- On reading issuepublic static int readInteger(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- Stream to readjava.io.IOException
- On reading issuepublic static long readLong(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- Stream to readjava.io.IOException
- On reading problempublic static int readStream(java.io.InputStream inputStream, byte[] array) throws java.io.IOException
readStream(inputStream, array, 0, array.length)
inputStream
- Stream to readarray
- Array to filljava.io.IOException
- On reading issuepublic static int readStream(java.io.InputStream inputStream, byte[] array, int offset) throws java.io.IOException
readStream(inputStream, array, offset, array.length -
offset)
inputStream
- Stream to readarray
- Array to filloffset
- To start writingjava.io.IOException
- On reading issuepublic static int readStream(java.io.InputStream inputStream, byte[] array, int offset, int length) throws java.io.IOException
inputStream
- Stream to readarray
- Array to filloffset
- To start writinglength
- Number of bytes to read at maximumjava.io.IOException
- On reading issuepublic static java.lang.String readString(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- Stream to readjava.io.IOException
- On reading issuepublic static void rename(java.io.File source, java.io.File destination) throws java.io.IOException
source
- File sourcedestination
- File destinationjava.io.IOException
- On rename issuepublic static void unzip(java.io.File directoryDestination, java.io.File zip) throws java.io.IOException
directoryDestination
- Directory where unzipzip
- Zip filejava.io.IOException
- On extracting issuepublic static void unzip(java.io.File directoryDestination, java.io.InputStream inputStreamZip) throws java.io.IOException
directoryDestination
- Directory where unzipinputStreamZip
- Stream to unzipjava.io.IOException
- On unzipping issuepublic static void write(java.io.File fileSource, java.io.File fileDestination) throws java.io.IOException
fileSource
- Source filefileDestination
- Destination filejava.io.IOException
- On copying issuepublic static void write(java.io.File fileSource, java.io.OutputStream outputStream) throws java.io.IOException
fileSource
- Source fileoutputStream
- Stream where writejava.io.IOException
- On copying issuepublic static void write(java.io.InputStream inputStream, java.io.File fileDestination) throws java.io.IOException
inputStream
- Stream sourcefileDestination
- File destinationjava.io.IOException
- On copying issuepublic static void write(java.io.InputStream inputStream, java.io.OutputStream outputStream) throws java.io.IOException
inputStream
- Stream sourceoutputStream
- Stream destinationjava.io.IOException
- On copying issuepublic static void writeBigInteger(java.math.BigInteger bigInteger, java.io.OutputStream outputStream) throws java.io.IOException
bigInteger
- BigInteger
to writeoutputStream
- Stream where writejava.io.IOException
- On writing issuepublic static void writeBinarizable(Binarizable binarizable, java.io.OutputStream outputStream) throws java.io.IOException
binarizable
- Binarizable
to writeoutputStream
- Stream where writejava.io.IOException
- On writing issuepublic static void writeBinarizableNamed(Binarizable binarizable, java.io.OutputStream outputStream) throws java.io.IOException
binarizable
- Binarizable
to writeoutputStream
- Stream where writejava.io.IOException
- On writing issuepublic static void writeByteArray(byte[] array, int offset, int length, java.io.OutputStream outputStream) throws java.io.IOException
array
- Array to writeoffset
- Offset where start read the arraylength
- Number of byte to writeoutputStream
- Stream where writejava.io.IOException
- On writing issuepublic static void writeByteArray(byte[] array, java.io.OutputStream outputStream) throws java.io.IOException
writeByteArray(array, 0, array.length, outputStream)
array
- Array to writeoutputStream
- Stream where writejava.io.IOException
- On writing issuepublic static void writeDouble(double d, java.io.OutputStream outputStream) throws java.io.IOException
d
- Double to writeoutputStream
- Stream where writejava.io.IOException
- On writing problempublic static void writeInteger(int integer, java.io.OutputStream outputStream) throws java.io.IOException
integer
- Integer to writeoutputStream
- Stream where writejava.io.IOException
- On writing issuepublic static void writeLong(long integer, java.io.OutputStream outputStream) throws java.io.IOException
integer
- Long to writeoutputStream
- Stream where writejava.io.IOException
- On writing problempublic static void writeString(java.lang.String string, java.io.OutputStream outputStream) throws java.io.IOException
string
- String to writeoutputStream
- Stream where writejava.io.IOException
- On writing issuepublic static void zip(java.io.File source, java.io.File destination) throws java.io.IOException
source
- File/directory to zipdestination
- File destinationjava.io.IOException
- On zipping issuepublic static void zip(java.io.File source, java.io.OutputStream outputStreamZip) throws java.io.IOException
source
- File/directory to zipoutputStreamZip
- Where write the zipjava.io.IOException
- On zipping issue