org.tranche.util
Class IOUtil

java.lang.Object
  extended by org.tranche.util.IOUtil

public class IOUtil
extends java.lang.Object

Various helper methods for serializing data for storage and transfer as well as reading data from disk or network.

Author:
Jayson Falkner - jfalkner@umich.edu, James "Augie" Hill - augman85@gmail.com, Bryan Smith - bryanesmith@gmail.com

Field Summary
static byte BYTE_FALSE
           
static byte BYTE_TRUE
           
 
Constructor Summary
IOUtil()
           
 
Method Summary
static void copyFile(java.io.File src, java.io.File dest)
          Copies any file in a memory-safe manner.
static java.lang.String createURL(java.lang.String host, int port, boolean secure)
          Builds a URL from parameters.
static java.lang.String createURL(TrancheServer dfs)
          Create a Tranche url from any TrancheServer.
static PropagationReturnWrapper deleteData(TrancheServer ts, java.security.cert.X509Certificate cert, java.security.PrivateKey key, BigHash hash)
           
static PropagationReturnWrapper deleteData(TrancheServer dfs, java.security.cert.X509Certificate cert, java.security.PrivateKey key, BigHash hash, java.lang.String[] hosts)
          Delete a particular chunk from a remote server.
static PropagationReturnWrapper deleteMetaData(TrancheServer dfs, java.security.cert.X509Certificate cert, java.security.PrivateKey key, BigHash hash)
          Delete a particular meta data chunk from a remote server.
static PropagationReturnWrapper deleteMetaData(TrancheServer dfs, java.security.cert.X509Certificate cert, java.security.PrivateKey key, BigHash hash, java.lang.String[] hosts)
          Delete a particular meta data chunk from selected servers through a remote server.
static PropagationReturnWrapper deleteMetaData(TrancheServer ts, java.security.cert.X509Certificate cert, java.security.PrivateKey key, java.lang.String uploaderName, java.lang.Long uploadTimestamp, java.lang.String relativePathInDataSet, BigHash hash)
           
static PropagationReturnWrapper deleteMetaData(TrancheServer dfs, java.security.cert.X509Certificate cert, java.security.PrivateKey key, java.lang.String uploaderName, java.lang.Long uploadTimestamp, java.lang.String relativePathInDataSet, BigHash hash, java.lang.String[] hosts)
           
static int findAvailablePort(int startPort, int endPort)
          Returns the first port in a range that is available on local machine.
static byte[] get1DBytes(PropagationReturnWrapper wrapper)
           
static byte[][] get2DBytes(PropagationReturnWrapper wrapper)
           
static byte[] getBytes(java.io.File f)
          Helper method to get all the bytes from a file using buffered IO..
static byte[] getBytes(java.io.InputStream in)
          Read in all the bytes from an InputStream.
static int getBytes(java.io.InputStream raf, byte[] buf)
          Helper method to transfer the given size of bytes from the InputStream to the OutputStream.
static void getBytes(java.io.InputStream in, java.io.OutputStream out)
          Read all the bytes from an InputStream and write them to an OutputStream.
static void getBytes(java.io.OutputStream out, java.io.InputStream is, long size)
          Helper method to transfer the given size of bytes from the InputStream to the OutputStream.
static void getBytes(java.io.RandomAccessFile raf, byte[] buf)
          Helper method to transfer the given size of bytes from the InputStream to the OutputStream.
static void getBytesFully(byte[] buffer, java.io.InputStream bais)
          Utility method to fill buffer with bytes from input stream.
static Configuration getConfiguration(TrancheServer dfs)
           
static Configuration getConfiguration(TrancheServer dfs, java.security.cert.X509Certificate cert, java.security.PrivateKey key)
          Deprecated. Use getConfiguration(TrancheServer) instead
static PropagationReturnWrapper getData(TrancheServer ts, BigHash hash, boolean propagateRequest)
           
static PropagationReturnWrapper getMetaData(TrancheServer ts, BigHash hash, boolean propagateRequest)
           
static byte[] getNonce(TrancheServer ts)
           
static byte[][] getNonces(TrancheServer ts, int count)
           
static byte[][] getNonces(TrancheServer ts, java.lang.String[] hosts)
           
static boolean hasData(TrancheServer ts, BigHash hash)
           
static boolean hasMetaData(TrancheServer ts, BigHash hash)
           
static java.lang.String parseHost(java.lang.String urlOrHost)
          Parse the host from the URL.
static int parsePort(java.lang.String url)
          Parses a port from a URL.
static java.lang.String parseProtocol(java.lang.String url)
          Parses a protocol (e.g., tranche://, http://, etc.) from a URL.
static boolean parseSecure(java.lang.String url)
           
static BigHash readBigHash(java.io.InputStream i)
           
static boolean readBoolean(java.io.InputStream i)
           
static byte readByte(java.io.InputStream i)
           
static byte[] readBytes(int byteCount, java.io.InputStream i)
          Read up to specified byte count from input stream.
static java.io.InputStream readData(java.io.InputStream i)
           
static byte[] readDataBytes(java.io.InputStream i)
           
static int readInt(java.io.InputStream i)
           
static java.lang.String readLine(java.io.BufferedReader is)
          Read a line from a BufferedReader.
static long readLong(java.io.InputStream i)
           
static java.lang.String readString(java.io.InputStream i)
           
static void recursiveCopyFiles(java.io.File src, java.io.File dest)
          Recursively copies from src to dest.
static void recursiveCopyFiles(java.io.File src, java.io.File dest, boolean shouldContinueIfDestExists)
          Recursively copies from src to dest.
static java.io.File recursiveDelete(java.io.File dir)
          Recursively deletes all the files in the directory.
static java.io.File recursiveDeleteWithWarning(java.io.File dir)
          Recursively deletes all the files in the directory.
static boolean renameFallbackCopy(java.io.File toRename, java.io.File renameTo)
          Helper method to attempt to rename a file.
static void requestShutdown(TrancheServer ts, java.security.cert.X509Certificate cert, java.security.PrivateKey key)
          Remotely request a shutdown.
static void safeClose(DataBlockUtil dbu)
          Helper method to safely close a DataBlockUtil.
static void safeClose(DiskBackedBigHashList list)
          Helper method to safely close disk-backed colletion.
static void safeClose(DiskBackedBigHashSet set)
          Helper method to safely close disk-backed colletion.
static void safeClose(java.io.InputStream in)
          Safely closes an InputStream by invoking the close() method.
static void safeClose(java.io.OutputStream out)
          A helper method to safely close the given OutputStream object via invoking flush() followed by close().
static void safeClose(ProjectFile pf)
          A helper method to safely close off any resources used by ProjectFile.
static void safeClose(java.io.RandomAccessFile ras)
          Safely close off resources used by RandomAccessFile.
static void safeClose(java.io.Reader in)
          Safely close off resources used by any Reader.
static void safeClose(Server server)
          Helper method to make sure that the DFS closes and that no exceptions are thrown, including NullPointerExceptions.
static void safeClose(java.net.ServerSocket serverSocket)
           
static void safeClose(java.net.Socket socket)
           
static void safeClose(TrancheServer dfs)
          Helper method to make sure that the DFS closes and that no exceptions are thrown, including NullPointerExceptions.
static void safeClose(java.io.Writer out)
          A helper method to safely close the given FileWriter object via invoking flush() followed by close().
static void safeDelete(java.io.File file)
          A helper method that trys really hard to make sure a file is deleted.
static void setBytes(byte[] bytes, java.io.File f)
          Set the bytes to a file.
static void setBytes(byte[] bytes, java.io.File f, boolean append)
          Set the bytes to a file.
static void setConfiguration(TrancheServer ts, Configuration config, java.security.cert.X509Certificate cert, java.security.PrivateKey key)
          Adding meta-data and data bytes is near-identical.
static PropagationReturnWrapper setData(TrancheServer ts, java.security.cert.X509Certificate cert, java.security.PrivateKey key, BigHash hash, byte[] bytesToUpload)
           
static PropagationReturnWrapper setData(TrancheServer dfs, java.security.cert.X509Certificate cert, java.security.PrivateKey key, BigHash hash, byte[] bytesToUpload, java.lang.String[] hosts)
           
static PropagationReturnWrapper setMetaData(TrancheServer ts, java.security.cert.X509Certificate cert, java.security.PrivateKey key, boolean merge, BigHash hash, byte[] bytesToUpload)
           
static PropagationReturnWrapper setMetaData(TrancheServer dfs, java.security.cert.X509Certificate cert, java.security.PrivateKey key, boolean merge, BigHash hash, byte[] bytesToUpload, java.lang.String[] hosts)
          Set the meta data bytes associated with the hash to selected servers through a particular TrancheServer.
static void writeBigHash(BigHash v, java.io.OutputStream o)
           
static void writeBoolean(boolean v, java.io.OutputStream o)
           
static void writeByte(byte v, java.io.OutputStream o)
           
static void writeBytes(byte[] v, java.io.OutputStream o)
           
static void writeData(byte[] v, java.io.OutputStream o)
           
static void writeInt(int v, java.io.OutputStream o)
           
static void writeLine(java.lang.String s, java.io.Writer w)
          Write a line to a Writer.
static void writeLong(long v, java.io.OutputStream o)
           
static void writeString(java.lang.String v, java.io.OutputStream o)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE_FALSE

public static final byte BYTE_FALSE
See Also:
Constant Field Values

BYTE_TRUE

public static final byte BYTE_TRUE
See Also:
Constant Field Values
Constructor Detail

IOUtil

public IOUtil()
Method Detail

getBytes

public static byte[] getBytes(java.io.File f)
                       throws java.io.IOException

Helper method to get all the bytes from a file using buffered IO..

Parameters:
f - File to read bytes from.
Returns:
A byte[] representing the contents of the file.
Throws:
java.io.IOException - If the file can't be found or if the file isn't readable.

setBytes

public static void setBytes(byte[] bytes,
                            java.io.File f)
                     throws java.io.IOException

Set the bytes to a file. Overwrites existing content (no append).

Parameters:
bytes -
f -
Throws:
java.io.IOException

setBytes

public static void setBytes(byte[] bytes,
                            java.io.File f,
                            boolean append)
                     throws java.io.IOException

Set the bytes to a file.

Parameters:
bytes -
f -
append - True if append, false otherwise
Throws:
java.io.IOException

getBytes

public static byte[] getBytes(java.io.InputStream in)
                       throws java.io.IOException

Read in all the bytes from an InputStream.

Note that these bytes are buffered in memory.

Parameters:
in -
Returns:
Throws:
java.io.IOException

getBytes

public static void getBytes(java.io.InputStream in,
                            java.io.OutputStream out)
                     throws java.io.IOException

Read all the bytes from an InputStream and write them to an OutputStream.

Buffers maximum of 10KB at a time.

Parameters:
in -
out -
Throws:
java.io.IOException

createURL

public static java.lang.String createURL(java.lang.String host,
                                         int port,
                                         boolean secure)

Builds a URL from parameters. Format: tranche://host:port or ssl+tranche://host:port

Parameters:
host -
port -
secure -
Returns:

createURL

public static java.lang.String createURL(TrancheServer dfs)

Create a Tranche url from any TrancheServer. If fails, returns null.

Returns:

safeClose

public static final void safeClose(ProjectFile pf)

A helper method to safely close off any resources used by ProjectFile. (Might use a DiskBackedProjectFilePartSet, which uses a temporary file.)

Parameters:
pf -

safeClose

public static final void safeClose(DataBlockUtil dbu)

Helper method to safely close a DataBlockUtil.

Parameters:
dbu -

safeClose

public static final void safeClose(java.io.OutputStream out)

A helper method to safely close the given OutputStream object via invoking flush() followed by close(). Any exceptions thorwn are discarded silently, including NullPointerExceptions that may be thrown if the reference is null.

Parameters:
out - OuputStream to safely close.

safeClose

public static final void safeClose(java.io.Writer out)

A helper method to safely close the given FileWriter object via invoking flush() followed by close(). Any exceptions thorwn are discarded silently, including NullPointerExceptions that may be thrown if the reference is null.

Parameters:
out - OuputStream to safely close.

safeClose

public static final void safeClose(java.io.InputStream in)

Safely closes an InputStream by invoking the close() method. Any errors thrown are silently discard, and no NullPointerException is thrown if the InputStream reference passed is null.

Parameters:
in - InpuStream to safely close.

safeClose

public static final void safeClose(java.io.RandomAccessFile ras)

Safely close off resources used by RandomAccessFile.

Parameters:
ras -

safeClose

public static void safeClose(java.io.Reader in)

Safely close off resources used by any Reader.

Parameters:
in -

safeClose

public static final void safeClose(DiskBackedBigHashSet set)

Helper method to safely close disk-backed colletion.

Parameters:
list -

safeClose

public static final void safeClose(DiskBackedBigHashList list)

Helper method to safely close disk-backed colletion.

Parameters:
list -

safeClose

public static final void safeClose(TrancheServer dfs)

Helper method to make sure that the DFS closes and that no exceptions are thrown, including NullPointerExceptions.

Parameters:
dfs - DistributedFileSystem instance to safely close.

safeClose

public static final void safeClose(Server server)

Helper method to make sure that the DFS closes and that no exceptions are thrown, including NullPointerExceptions.

Parameters:
server - passed in Server

safeClose

public static final void safeClose(java.net.Socket socket)
Parameters:
socket -

safeClose

public static final void safeClose(java.net.ServerSocket serverSocket)
Parameters:
serverSocket -

safeDelete

public static void safeDelete(java.io.File file)

A helper method that trys really hard to make sure a file is deleted. If the file can't be deleted, it is reduced to a size of 1. This method is particuarlly helpful for the Knoppix LiveCDs and making sure temporary files are deleted. If they aren't they'll quickly saturate the ramdisk and cause "Out of disk space" errors.

Parameters:
file - The file to delete.

recursiveDelete

public static java.io.File recursiveDelete(java.io.File dir)

Recursively deletes all the files in the directory. If fails, throws RuntimeException.

Parameters:
dir -
Returns:
The directory passed as a parameter.

recursiveDeleteWithWarning

public static final java.io.File recursiveDeleteWithWarning(java.io.File dir)

Recursively deletes all the files in the directory. If the deletion can't completely finish, show a warning.

Parameters:
dir -
Returns:
The directory passed as a parameter.

getBytes

public static final void getBytes(java.io.OutputStream out,
                                  java.io.InputStream is,
                                  long size)
                           throws java.io.IOException

Helper method to transfer the given size of bytes from the InputStream to the OutputStream. Reasonably buffered.

Parameters:
out -
is -
size - Maximum bytes to read.
Throws:
java.io.IOException

getBytes

public static final void getBytes(java.io.RandomAccessFile raf,
                                  byte[] buf)
                           throws java.io.IOException

Helper method to transfer the given size of bytes from the InputStream to the OutputStream. Reasonably buffered.

Parameters:
raf -
buf -
Throws:
java.io.IOException

getBytes

public static final int getBytes(java.io.InputStream raf,
                                 byte[] buf)
                          throws java.io.IOException

Helper method to transfer the given size of bytes from the InputStream to the OutputStream. Reasonably buffered.

Parameters:
raf -
buf -
Returns:
Throws:
java.io.IOException

getBytesFully

public static final void getBytesFully(byte[] buffer,
                                       java.io.InputStream bais)
                                throws java.io.IOException

Utility method to fill buffer with bytes from input stream.

Throws an IOException if reaches end of stream before reading all bytes.

Parameters:
buffer -
bais -
Throws:
java.io.IOException

hasData

public static final boolean hasData(TrancheServer ts,
                                    BigHash hash)
                             throws java.lang.Exception
Parameters:
ts -
hash -
Returns:
Throws:
java.lang.Exception

hasMetaData

public static final boolean hasMetaData(TrancheServer ts,
                                        BigHash hash)
                                 throws java.lang.Exception
Parameters:
ts -
hash -
Returns:
Throws:
java.lang.Exception

setMetaData

public static final PropagationReturnWrapper setMetaData(TrancheServer ts,
                                                         java.security.cert.X509Certificate cert,
                                                         java.security.PrivateKey key,
                                                         boolean merge,
                                                         BigHash hash,
                                                         byte[] bytesToUpload)
                                                  throws java.lang.Exception
Parameters:
ts -
cert -
key -
merge -
hash -
bytesToUpload -
Returns:
Throws:
java.lang.Exception

setMetaData

public static final PropagationReturnWrapper setMetaData(TrancheServer dfs,
                                                         java.security.cert.X509Certificate cert,
                                                         java.security.PrivateKey key,
                                                         boolean merge,
                                                         BigHash hash,
                                                         byte[] bytesToUpload,
                                                         java.lang.String[] hosts)
                                                  throws java.lang.Exception

Set the meta data bytes associated with the hash to selected servers through a particular TrancheServer. The chunk will be signed.

Parameters:
dfs -
cert -
key -
merge -
hash -
bytesToUpload -
hosts -
Returns:
Throws:
java.lang.Exception

setData

public static final PropagationReturnWrapper setData(TrancheServer ts,
                                                     java.security.cert.X509Certificate cert,
                                                     java.security.PrivateKey key,
                                                     BigHash hash,
                                                     byte[] bytesToUpload)
                                              throws java.lang.Exception
Parameters:
ts -
cert -
key -
hash -
bytesToUpload -
Returns:
Throws:
java.lang.Exception

setData

public static final PropagationReturnWrapper setData(TrancheServer dfs,
                                                     java.security.cert.X509Certificate cert,
                                                     java.security.PrivateKey key,
                                                     BigHash hash,
                                                     byte[] bytesToUpload,
                                                     java.lang.String[] hosts)
                                              throws java.lang.Exception
Parameters:
dfs -
cert -
key -
hash -
bytesToUpload -
hosts -
Returns:
Throws:
java.lang.Exception

getNonce

public static final byte[] getNonce(TrancheServer ts)
                             throws java.lang.Exception
Parameters:
ts -
Returns:
Throws:
java.lang.Exception

getNonces

public static final byte[][] getNonces(TrancheServer ts,
                                       java.lang.String[] hosts)
                                throws java.lang.Exception
Parameters:
ts -
hosts -
Returns:
Throws:
java.lang.Exception

getNonces

public static final byte[][] getNonces(TrancheServer ts,
                                       int count)
                                throws java.lang.Exception
Parameters:
ts -
count -
Returns:
Throws:
java.lang.Exception

getConfiguration

public static final Configuration getConfiguration(TrancheServer dfs,
                                                   java.security.cert.X509Certificate cert,
                                                   java.security.PrivateKey key)
                                            throws java.lang.Exception
Deprecated. Use getConfiguration(TrancheServer) instead

Parameters:
dfs -
cert -
key -
Returns:
Throws:
java.lang.Exception

getConfiguration

public static final Configuration getConfiguration(TrancheServer dfs)
                                            throws java.lang.Exception
Parameters:
dfs -
Returns:
Throws:
java.lang.Exception

requestShutdown

public static final void requestShutdown(TrancheServer ts,
                                         java.security.cert.X509Certificate cert,
                                         java.security.PrivateKey key)
                                  throws java.lang.Exception

Remotely request a shutdown. Uses certificate and private key to authenticate user remotely.

Requires administrative privileges on remote server.

Parameters:
ts -
cert -
key -
Throws:
java.lang.Exception

setConfiguration

public static final void setConfiguration(TrancheServer ts,
                                          Configuration config,
                                          java.security.cert.X509Certificate cert,
                                          java.security.PrivateKey key)
                                   throws java.lang.Exception

Adding meta-data and data bytes is near-identical. This method abstracts that work.

Parameters:
ts -
config -
cert -
key -
Throws:
java.lang.Exception

getData

public static final PropagationReturnWrapper getData(TrancheServer ts,
                                                     BigHash hash,
                                                     boolean propagateRequest)
                                              throws java.lang.Exception
Parameters:
ts -
hash -
propagateRequest -
Returns:
Throws:
java.lang.Exception

get1DBytes

public static final byte[] get1DBytes(PropagationReturnWrapper wrapper)
Parameters:
wrapper -
Returns:

get2DBytes

public static final byte[][] get2DBytes(PropagationReturnWrapper wrapper)
Parameters:
wrapper -
Returns:

getMetaData

public static final PropagationReturnWrapper getMetaData(TrancheServer ts,
                                                         BigHash hash,
                                                         boolean propagateRequest)
                                                  throws java.lang.Exception
Parameters:
ts -
hash -
propagateRequest -
Returns:
Throws:
java.lang.Exception

deleteData

public static final PropagationReturnWrapper deleteData(TrancheServer ts,
                                                        java.security.cert.X509Certificate cert,
                                                        java.security.PrivateKey key,
                                                        BigHash hash)
                                                 throws java.lang.Exception
Parameters:
ts -
cert -
key -
hash -
Returns:
Throws:
java.lang.Exception

deleteData

public static final PropagationReturnWrapper deleteData(TrancheServer dfs,
                                                        java.security.cert.X509Certificate cert,
                                                        java.security.PrivateKey key,
                                                        BigHash hash,
                                                        java.lang.String[] hosts)
                                                 throws java.lang.Exception

Delete a particular chunk from a remote server.

Requires appropriate privileges. Uses certificate and key to remotely authenticate.

Parameters:
dfs -
cert -
key -
hash -
hosts -
Returns:
Throws:
java.lang.Exception

deleteMetaData

public static final PropagationReturnWrapper deleteMetaData(TrancheServer dfs,
                                                            java.security.cert.X509Certificate cert,
                                                            java.security.PrivateKey key,
                                                            BigHash hash)
                                                     throws java.lang.Exception

Delete a particular meta data chunk from a remote server.

Requires appropriate privileges. Uses certificate and key to remotely authenticate.

Parameters:
dfs -
cert -
key -
hash -
Throws:
java.lang.Exception

deleteMetaData

public static final PropagationReturnWrapper deleteMetaData(TrancheServer dfs,
                                                            java.security.cert.X509Certificate cert,
                                                            java.security.PrivateKey key,
                                                            BigHash hash,
                                                            java.lang.String[] hosts)
                                                     throws java.lang.Exception

Delete a particular meta data chunk from selected servers through a remote server.

Requires appropriate privileges. Uses certificate and key to remotely authenticate.

Parameters:
dfs -
cert -
key -
hash -
hosts -
Throws:
java.lang.Exception

deleteMetaData

public static final PropagationReturnWrapper deleteMetaData(TrancheServer ts,
                                                            java.security.cert.X509Certificate cert,
                                                            java.security.PrivateKey key,
                                                            java.lang.String uploaderName,
                                                            java.lang.Long uploadTimestamp,
                                                            java.lang.String relativePathInDataSet,
                                                            BigHash hash)
                                                     throws java.lang.Exception
Parameters:
ts -
cert -
key -
uploaderName -
uploadTimestamp -
relativePathInDataSet -
hash -
Returns:
Throws:
java.lang.Exception

deleteMetaData

public static final PropagationReturnWrapper deleteMetaData(TrancheServer dfs,
                                                            java.security.cert.X509Certificate cert,
                                                            java.security.PrivateKey key,
                                                            java.lang.String uploaderName,
                                                            java.lang.Long uploadTimestamp,
                                                            java.lang.String relativePathInDataSet,
                                                            BigHash hash,
                                                            java.lang.String[] hosts)
                                                     throws java.lang.Exception
Parameters:
dfs -
cert -
key -
uploaderName -
uploadTimestamp -
relativePathInDataSet -
hash -
hosts -
Returns:
Throws:
java.lang.Exception

writeLine

public static final void writeLine(java.lang.String s,
                                   java.io.Writer w)
                            throws java.io.IOException

Write a line to a Writer. Safely escapes backslashes and newlines.

Parameters:
s -
w -
Throws:
java.io.IOException

readLine

public static final java.lang.String readLine(java.io.BufferedReader is)
                                       throws java.io.IOException

Read a line from a BufferedReader. Unescapes backslashes and newlines.

Parameters:
is -
Returns:
Throws:
java.io.IOException

renameFallbackCopy

public static final boolean renameFallbackCopy(java.io.File toRename,
                                               java.io.File renameTo)

Helper method to attempt to rename a file. If a soft link fails (e.g. rename across disks) attempt a slower hard copy.

Parameters:
toRename -
renameTo -
Returns:

parseProtocol

public static java.lang.String parseProtocol(java.lang.String url)
                                      throws java.lang.Exception

Parses a protocol (e.g., tranche://, http://, etc.) from a URL.

Parameters:
url -
Returns:
Throws:
java.lang.Exception

parsePort

public static int parsePort(java.lang.String url)
                     throws java.lang.Exception

Parses a port from a URL.

Parameters:
url -
Returns:
Throws:
java.lang.Exception

parseSecure

public static boolean parseSecure(java.lang.String url)
                           throws java.lang.Exception
Parameters:
url -
Returns:
Throws:
java.lang.Exception

parseHost

public static java.lang.String parseHost(java.lang.String urlOrHost)

Parse the host from the URL. Generally used for the IP, though handles host names, too.

Parameters:
urlOrHost -
Returns:

copyFile

public static void copyFile(java.io.File src,
                            java.io.File dest)
                     throws java.io.IOException

Copies any file in a memory-safe manner.

Parameters:
src -
dest - If any data exists, it will be over-written (clobbered).
Throws:
java.io.IOException

recursiveCopyFiles

public static void recursiveCopyFiles(java.io.File src,
                                      java.io.File dest)
                               throws java.io.IOException

Recursively copies from src to dest. File can reference directories or normal files.

Parameters:
src -
dest -
Throws:
java.io.IOException

recursiveCopyFiles

public static void recursiveCopyFiles(java.io.File src,
                                      java.io.File dest,
                                      boolean shouldContinueIfDestExists)
                               throws java.io.IOException

Recursively copies from src to dest. File can reference directories or normal files.

Parameters:
src -
dest -
shouldContinueIfDestExists - True if want to copy even if destination; false will throw an exception if destination exists
Throws:
java.io.IOException

findAvailablePort

public static int findAvailablePort(int startPort,
                                    int endPort)

Returns the first port in a range that is available on local machine. Returns -1 if none available.

Parameters:
startPort -
endPort -
Returns:

writeBigHash

public static final void writeBigHash(BigHash v,
                                      java.io.OutputStream o)
                               throws java.io.IOException
Throws:
java.io.IOException

readBigHash

public static final BigHash readBigHash(java.io.InputStream i)
                                 throws java.io.IOException
Throws:
java.io.IOException

writeString

public static final void writeString(java.lang.String v,
                                     java.io.OutputStream o)
                              throws java.io.IOException
Throws:
java.io.IOException

readString

public static final java.lang.String readString(java.io.InputStream i)
                                         throws java.io.IOException
Throws:
java.io.IOException

writeBoolean

public static final void writeBoolean(boolean v,
                                      java.io.OutputStream o)
                               throws java.io.IOException
Throws:
java.io.IOException

readBoolean

public static final boolean readBoolean(java.io.InputStream i)
                                 throws java.io.IOException
Throws:
java.io.IOException

writeLong

public static final void writeLong(long v,
                                   java.io.OutputStream o)
                            throws java.io.IOException
Throws:
java.io.IOException

readLong

public static final long readLong(java.io.InputStream i)
                           throws java.io.IOException
Throws:
java.io.IOException

writeInt

public static final void writeInt(int v,
                                  java.io.OutputStream o)
                           throws java.io.IOException
Throws:
java.io.IOException

readInt

public static final int readInt(java.io.InputStream i)
                         throws java.io.IOException
Throws:
java.io.IOException

writeData

public static final void writeData(byte[] v,
                                   java.io.OutputStream o)
                            throws java.io.IOException
Throws:
java.io.IOException

readDataBytes

public static final byte[] readDataBytes(java.io.InputStream i)
                                  throws java.io.IOException
Throws:
java.io.IOException

readData

public static final java.io.InputStream readData(java.io.InputStream i)
                                          throws java.io.IOException
Throws:
java.io.IOException

writeBytes

public static final void writeBytes(byte[] v,
                                    java.io.OutputStream o)
                             throws java.io.IOException
Throws:
java.io.IOException

readBytes

public static final byte[] readBytes(int byteCount,
                                     java.io.InputStream i)
                              throws java.io.IOException

Read up to specified byte count from input stream. Stops on following two conditions:

If reach end of stream and less bytes were read than the specified byte count, the resulting byte array will be trimmed to the size of the bytes read.

Parameters:
byteCount -
i -
Returns:
Throws:
java.io.IOException

writeByte

public static final void writeByte(byte v,
                                   java.io.OutputStream o)
                            throws java.io.IOException
Throws:
java.io.IOException

readByte

public static final byte readByte(java.io.InputStream i)
                           throws java.io.IOException
Throws:
java.io.IOException


This code is free for use both commercially and non-commercially as stated in the project's license