com.dyuproject.util
Class ResourceUtil

java.lang.Object
  extended by com.dyuproject.util.ResourceUtil

public final class ResourceUtil
extends Object

Util for files and streams.

Author:
David Yu

Constructor Summary
ResourceUtil()
           
 
Method Summary
static void copy(File in, File out)
          Copies the contents of the input file to the output file.
static void copy(InputStream in, OutputStream out)
          Copies the contents of the input stream to the output stream.
static void copy(InputStream in, OutputStream out, int bufferSize)
          Copies the contents of the input stream to the output stream with the specified buffer size to use for copying.
static void copy(URL in, File out)
          Copies the contents of the input url to the output file.
static void copy(URL in, URL out)
          Copies the contents of the input url to the output url.
static void copyFileToDir(File file, File dirTo)
          Copies the given file to the given dir.
static ByteArrayOutputStream getByteArrayOutputStream(InputStream in)
          Gets the ByteArrayOutputStream that was filled when reading from the given input stream in.
static int getCopyBufferSize()
          Gets the buffer size to use when copying data from streams.
static List<File> getFilesByExtension(File dir, String[] extensions)
          Returns a list of file filtered by their file types/extensions; (E.g ".zip")
static byte[] readBytes(File file)
          Reads the contents of the file into a byte array.
static byte[] readBytes(InputStream in)
          Reads the contents of the given input stream into a byte array.
static byte[] readBytes(String file)
          Reads the contents of the given file into a byte array.
static byte[] readBytes(URI file)
          Reads the contents of the given file into a byte array.
static byte[] readBytes(URL file)
          Reads the contents of the given file into a byte array.
static void setCopyBufferSize(int size)
          Sets the buffer size to use when copying data from streams.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceUtil

public ResourceUtil()
Method Detail

setCopyBufferSize

public static void setCopyBufferSize(int size)
Sets the buffer size to use when copying data from streams.


getCopyBufferSize

public static int getCopyBufferSize()
Gets the buffer size to use when copying data from streams.


readBytes

public static byte[] readBytes(File file)
                        throws IOException
Reads the contents of the file into a byte array.

Throws:
IOException

readBytes

public static byte[] readBytes(String file)
                        throws IOException
Reads the contents of the given file into a byte array.

Throws:
IOException

readBytes

public static byte[] readBytes(URI file)
                        throws IOException
Reads the contents of the given file into a byte array.

Throws:
IOException

readBytes

public static byte[] readBytes(URL file)
                        throws IOException
Reads the contents of the given file into a byte array.

Throws:
IOException

readBytes

public static byte[] readBytes(InputStream in)
                        throws IOException
Reads the contents of the given input stream into a byte array.

Throws:
IOException

getByteArrayOutputStream

public static ByteArrayOutputStream getByteArrayOutputStream(InputStream in)
                                                      throws IOException
Gets the ByteArrayOutputStream that was filled when reading from the given input stream in.

Throws:
IOException

copy

public static void copy(URL in,
                        URL out)
                 throws IOException
Copies the contents of the input url to the output url.

Throws:
IOException

copy

public static void copy(File in,
                        File out)
                 throws IOException
Copies the contents of the input file to the output file.

Throws:
IOException

copy

public static void copy(URL in,
                        File out)
                 throws IOException
Copies the contents of the input url to the output file.

Throws:
IOException

copy

public static void copy(InputStream in,
                        OutputStream out)
                 throws IOException
Copies the contents of the input stream to the output stream.

Throws:
IOException

copy

public static void copy(InputStream in,
                        OutputStream out,
                        int bufferSize)
                 throws IOException
Copies the contents of the input stream to the output stream with the specified buffer size to use for copying.

Throws:
IOException

copyFileToDir

public static void copyFileToDir(File file,
                                 File dirTo)
                          throws IOException
Copies the given file to the given dir.

Throws:
IOException

getFilesByExtension

public static List<File> getFilesByExtension(File dir,
                                             String[] extensions)
Returns a list of file filtered by their file types/extensions; (E.g ".zip")



Copyright © 2008-2013. All Rights Reserved.