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 long
calcCRC(InputStream in)
static void
copy(File in, File out)
Copies one file to another.static void
copy(File in, OutputStream out)
static void
copy(InputStream in, File outputFile)
Copies anInputStream
to a File.static void
copy(InputStream is, OutputStream outputStream)
Copies anInputStream
to anOutputStream
.static void
copy(InputStream is, String outputPath)
Copies anInputStream
to a File.static void
copy(String fromPath, String toPath, boolean move)
Copies a file from one location to another.static void
copy(ReadableByteChannel inChannel, WritableByteChannel outChannel)
Copies aReadableByteChannel
to aWritableByteChannel
.static void
copy(ReadableByteChannel inChannel, WritableByteChannel outChannel, boolean closeChannels)
Copies aReadableByteChannel
to aWritableByteChannel
.static FileCachedInputStream
createResettableStream(InputStream is, int bufferSize)
static byte[]
inputStreamToBytes(InputStream in)
Reads an InputStream into an array of bytes.boolean
isCompressed(byte[] bytes)
static String
streamAsString(InputStream in, String encoding)
static String
streamUtf8AsString(InputStream in)
static InputStream
stringAsStream(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 aReadableByteChannel
to 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 aReadableByteChannel
to 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 anInputStream
to 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 anInputStream
to 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 anInputStream
to 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)
-
-