Package com.logicaldoc.util.io
Class IOUtil
java.lang.Object
com.logicaldoc.util.io.IOUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Close the given resource.static Object
deserialize
(String xml) Deserializes an XML serialization to obtain the objectstatic void
Downloads an URL into a local filestatic byte[]
getBytesOfStream
(InputStream stream) static InputStream
getLimitedStream
(InputStream input, long limit) Creates a new input stream that represents the first part of the original stream.static String
static String
serialize
(Serializable object, String charset) Serializes an object into XML stringstatic void
write
(InputStream input, File output) static void
write
(InputStream input, OutputStream output)
-
Method Details
-
close
Close the given resource.- Parameters:
resource
- The resource to be closed.
-
getLimitedStream
Creates a new input stream that represents the first part of the original stream.- Parameters:
input
- Original input streamlimit
- Size of the new stream, expressed in bytes- Returns:
- the limited input stream
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
readStream
- Throws:
IOException
-
getBytesOfStream
- Throws:
IOException
-
serialize
Serializes an object into XML string- Parameters:
object
- The object to serializecharset
- The charset to use for the output, if not provided UTF-8 is used instead- Returns:
- The serialized string
-
deserialize
Deserializes an XML serialization to obtain the object- Parameters:
xml
- The XML content- Returns:
- The recovered object
-
download
public static void download(String url, File dest, int timeout, int bufferSize) throws IOException, URISyntaxException Downloads an URL into a local file- Parameters:
url
- The URL to downloaddest
- The destination local filetimeout
- A connection timeout in secondsbufferSize
- The buffer size in bytes- Throws:
IOException
- I/O errorURISyntaxException
- The URL is invalid
-