Package net.sf.okapi.common
Class StreamUtil
- java.lang.Object
-
- net.sf.okapi.common.StreamUtil
-
public class StreamUtil extends Object
Various manipulations of streams, files, etc. Most methods rewrap IOException as OkapiIOException.
-
-
Constructor Summary
Constructors Constructor Description StreamUtil()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static longcalcCRC(InputStream in)static voidcopy(File in, File out)Copies one file to another.static voidcopy(File in, OutputStream out)static voidcopy(InputStream in, File outputFile)Copies anInputStreamto a File.static voidcopy(InputStream is, OutputStream outputStream)Copies anInputStreamto anOutputStream.static voidcopy(InputStream is, String outputPath)Copies anInputStreamto a File.static voidcopy(String fromPath, String toPath, boolean move)Copies a file from one location to another.static voidcopy(ReadableByteChannel inChannel, WritableByteChannel outChannel)Copies aReadableByteChannelto aWritableByteChannel.static voidcopy(ReadableByteChannel inChannel, WritableByteChannel outChannel, boolean closeChannels)Copies aReadableByteChannelto aWritableByteChannel.static FileCachedInputStreamcreateResettableStream(InputStream is, int bufferSize)static byte[]inputStreamToBytes(InputStream in)Reads an InputStream into an array of bytes.booleanisCompressed(byte[] bytes)static StringstreamAsString(InputStream in, String encoding)static StringstreamUtf8AsString(InputStream in)static InputStreamstringAsStream(String str, String encoding)
-
-
-
Method Detail
-
inputStreamToBytes
public static byte[] inputStreamToBytes(InputStream in) throws IOException
Reads an InputStream into an array of bytes.- Parameters:
in- the input stream to read.- Returns:
- the array of bytes read.
- Throws:
IOException- if an error occurs.
-
copy
public static void copy(File in, OutputStream out)
-
streamAsString
public static String streamAsString(InputStream in, String encoding)
-
streamUtf8AsString
public static String streamUtf8AsString(InputStream in)
-
stringAsStream
public static InputStream stringAsStream(String str, String encoding)
-
calcCRC
public static long calcCRC(InputStream in)
-
copy
public static void copy(ReadableByteChannel inChannel, WritableByteChannel outChannel)
Copies aReadableByteChannelto aWritableByteChannel.- Parameters:
inChannel- the input Channel.outChannel- the output Channel.- Throws:
OkapiIOException- if an error occurs.
-
copy
public static void copy(ReadableByteChannel inChannel, WritableByteChannel outChannel, boolean closeChannels)
Copies aReadableByteChannelto aWritableByteChannel.- Parameters:
inChannel- the input Channel.outChannel- the output Channel.closeChannels- close in and out channels?- Throws:
OkapiIOException- if an error occurs.
-
copy
public static void copy(InputStream in, File outputFile)
Copies anInputStreamto a File.- Parameters:
in- the input stream.outputFile- the outputFile.- Throws:
OkapiIOException- if an error occurs.
-
copy
public static void copy(InputStream is, String outputPath)
Copies anInputStreamto a File.- Parameters:
is- the input stream.outputPath- the output path.- Throws:
OkapiIOException- if an error occurs.
-
copy
public static void copy(InputStream is, OutputStream outputStream)
Copies anInputStreamto anOutputStream.- Parameters:
is- the input stream.outputStream- the output stream.- Throws:
OkapiIOException- if an error occurs.
-
copy
public static void copy(File in, File out)
Copies one file to another.- Parameters:
in- the input file.out- the output file.- Throws:
OkapiIOException- if an error occurs.
-
copy
public static void copy(String fromPath, String toPath, boolean move)
Copies a file from one location to another.- Parameters:
fromPath- the path of the file to copy.toPath- the path of the copy to make.move- true to move the file, false to copy it.- Throws:
OkapiIOException- if an error occurs.
-
createResettableStream
public static FileCachedInputStream createResettableStream(InputStream is, int bufferSize) throws IOException
- Throws:
IOException
-
isCompressed
public boolean isCompressed(byte[] bytes)
-
-