Package com.cedarsoftware.util
Class IOUtilities
- java.lang.Object
-
- com.cedarsoftware.util.IOUtilities
-
public final class IOUtilities extends Object
Useful IOUtilities that simplify common io tasks- Author:
- Ken Partlow, John DeRegnaucourt (john@cedarsoftware.com)
Copyright (c) Cedar Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceIOUtilities.TransferCallback
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(Closeable c)static voidclose(XMLStreamReader reader)static voidclose(XMLStreamWriter writer)static byte[]compressBytes(byte[] bytes)static byte[]compressBytes(byte[] bytes, int offset, int len)static voidcompressBytes(FastByteArrayOutputStream original, FastByteArrayOutputStream compressed)static voidcompressBytes(ByteArrayOutputStream original, ByteArrayOutputStream compressed)static voidflush(Flushable f)static voidflush(XMLStreamWriter writer)static InputStreamgetInputStream(URLConnection c)static byte[]inputStreamToBytes(InputStream in)Convert InputStream contents to a byte[].static voidtransfer(File file, OutputStream out)static voidtransfer(File f, URLConnection c, IOUtilities.TransferCallback cb)static voidtransfer(InputStream in, byte[] bytes)Use this when you expect a byte[] length of bytes to be read from the InputStreamstatic voidtransfer(InputStream s, File f, IOUtilities.TransferCallback cb)static voidtransfer(InputStream in, OutputStream out)Transfers bytes from an input stream to an output stream.static voidtransfer(InputStream in, OutputStream out, IOUtilities.TransferCallback cb)Transfers bytes from an input stream to an output stream.static voidtransfer(URLConnection c, byte[] bytes)Transfers a byte[] to the output stream of a URLConnectionstatic voidtransfer(URLConnection c, File f, IOUtilities.TransferCallback cb)static byte[]uncompressBytes(byte[] bytes)static byte[]uncompressBytes(byte[] bytes, int offset, int len)
-
-
-
Method Detail
-
getInputStream
public static InputStream getInputStream(URLConnection c) throws IOException
- Throws:
IOException
-
transfer
public static void transfer(File f, URLConnection c, IOUtilities.TransferCallback cb) throws Exception
- Throws:
Exception
-
transfer
public static void transfer(URLConnection c, File f, IOUtilities.TransferCallback cb) throws Exception
- Throws:
Exception
-
transfer
public static void transfer(InputStream s, File f, IOUtilities.TransferCallback cb) throws Exception
- Throws:
Exception
-
transfer
public static void transfer(InputStream in, OutputStream out, IOUtilities.TransferCallback cb) throws IOException
Transfers bytes from an input stream to an output stream. Callers of this method are responsible for closing the streams since they are the ones that opened the streams.- Throws:
IOException
-
transfer
public static void transfer(InputStream in, byte[] bytes) throws IOException
Use this when you expect a byte[] length of bytes to be read from the InputStream- Throws:
IOException
-
transfer
public static void transfer(InputStream in, OutputStream out) throws IOException
Transfers bytes from an input stream to an output stream. Callers of this method are responsible for closing the streams since they are the ones that opened the streams.- Throws:
IOException
-
transfer
public static void transfer(File file, OutputStream out) throws IOException
- Throws:
IOException
-
close
public static void close(XMLStreamReader reader)
-
close
public static void close(XMLStreamWriter writer)
-
close
public static void close(Closeable c)
-
flush
public static void flush(Flushable f)
-
flush
public static void flush(XMLStreamWriter writer)
-
inputStreamToBytes
public static byte[] inputStreamToBytes(InputStream in)
Convert InputStream contents to a byte[]. Will return null on error. Only use this API if you know that the stream length will be relatively small.
-
transfer
public static void transfer(URLConnection c, byte[] bytes) throws IOException
Transfers a byte[] to the output stream of a URLConnection- Parameters:
c- Connection to transfer outputbytes- the bytes to send- Throws:
IOException
-
compressBytes
public static void compressBytes(ByteArrayOutputStream original, ByteArrayOutputStream compressed) throws IOException
- Throws:
IOException
-
compressBytes
public static void compressBytes(FastByteArrayOutputStream original, FastByteArrayOutputStream compressed) throws IOException
- Throws:
IOException
-
compressBytes
public static byte[] compressBytes(byte[] bytes)
-
compressBytes
public static byte[] compressBytes(byte[] bytes, int offset, int len)
-
uncompressBytes
public static byte[] uncompressBytes(byte[] bytes)
-
uncompressBytes
public static byte[] uncompressBytes(byte[] bytes, int offset, int len)
-
-