org.elasticsearch.common.io
Class Streams

java.lang.Object
  extended by org.elasticsearch.common.io.Streams

public abstract class Streams
extends Object

Simple utility methods for file and stream copying. All copy methods use a block size of 4096 bytes, and close all affected streams when done.

Mainly for use within the framework, but also useful for application code.


Field Summary
static int BUFFER_SIZE
           
 
Constructor Summary
Streams()
           
 
Method Summary
static void copy(byte[] in, File out)
          Copy the contents of the given byte array to the given output File.
static void copy(byte[] in, OutputStream out)
          Copy the contents of the given byte array to the given OutputStream.
static long copy(File in, File out)
          Copy the contents of the given input File to the given output File.
static long copy(InputStream in, OutputStream out)
           
static long copy(InputStream in, OutputStream out, byte[] buffer)
          Copy the contents of the given InputStream to the given OutputStream.
static int copy(Reader in, Writer out)
          Copy the contents of the given Reader to the given Writer.
static void copy(String in, Writer out)
          Copy the contents of the given String to the given output Writer.
static byte[] copyToByteArray(File in)
          Copy the contents of the given input File into a new byte array.
static byte[] copyToByteArray(InputStream in)
          Copy the contents of the given InputStream into a new byte array.
static byte[] copyToBytesFromClasspath(String path)
           
static String copyToString(Reader in)
          Copy the contents of the given Reader into a String.
static String copyToStringFromClasspath(ClassLoader classLoader, String path)
           
static String copyToStringFromClasspath(String path)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

public static final int BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

Streams

public Streams()
Method Detail

copy

public static long copy(File in,
                        File out)
                 throws IOException
Copy the contents of the given input File to the given output File.

Parameters:
in - the file to copy from
out - the file to copy to
Returns:
the number of bytes copied
Throws:
IOException - in case of I/O errors

copy

public static void copy(byte[] in,
                        File out)
                 throws IOException
Copy the contents of the given byte array to the given output File.

Parameters:
in - the byte array to copy from
out - the file to copy to
Throws:
IOException - in case of I/O errors

copyToByteArray

public static byte[] copyToByteArray(File in)
                              throws IOException
Copy the contents of the given input File into a new byte array.

Parameters:
in - the file to copy from
Returns:
the new byte array that has been copied to
Throws:
IOException - in case of I/O errors

copy

public static long copy(InputStream in,
                        OutputStream out)
                 throws IOException
Throws:
IOException

copy

public static long copy(InputStream in,
                        OutputStream out,
                        byte[] buffer)
                 throws IOException
Copy the contents of the given InputStream to the given OutputStream. Closes both streams when done.

Parameters:
in - the stream to copy from
out - the stream to copy to
Returns:
the number of bytes copied
Throws:
IOException - in case of I/O errors

copy

public static void copy(byte[] in,
                        OutputStream out)
                 throws IOException
Copy the contents of the given byte array to the given OutputStream. Closes the stream when done.

Parameters:
in - the byte array to copy from
out - the OutputStream to copy to
Throws:
IOException - in case of I/O errors

copyToByteArray

public static byte[] copyToByteArray(InputStream in)
                              throws IOException
Copy the contents of the given InputStream into a new byte array. Closes the stream when done.

Parameters:
in - the stream to copy from
Returns:
the new byte array that has been copied to
Throws:
IOException - in case of I/O errors

copy

public static int copy(Reader in,
                       Writer out)
                throws IOException
Copy the contents of the given Reader to the given Writer. Closes both when done.

Parameters:
in - the Reader to copy from
out - the Writer to copy to
Returns:
the number of characters copied
Throws:
IOException - in case of I/O errors

copy

public static void copy(String in,
                        Writer out)
                 throws IOException
Copy the contents of the given String to the given output Writer. Closes the write when done.

Parameters:
in - the String to copy from
out - the Writer to copy to
Throws:
IOException - in case of I/O errors

copyToString

public static String copyToString(Reader in)
                           throws IOException
Copy the contents of the given Reader into a String. Closes the reader when done.

Parameters:
in - the reader to copy from
Returns:
the String that has been copied to
Throws:
IOException - in case of I/O errors

copyToStringFromClasspath

public static String copyToStringFromClasspath(ClassLoader classLoader,
                                               String path)
                                        throws IOException
Throws:
IOException

copyToStringFromClasspath

public static String copyToStringFromClasspath(String path)
                                        throws IOException
Throws:
IOException

copyToBytesFromClasspath

public static byte[] copyToBytesFromClasspath(String path)
                                       throws IOException
Throws:
IOException


Copyright © 2009-2012. All Rights Reserved.