|
TV-Browser 3.3.3 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object util.io.IOUtilities
public class IOUtilities
A utilities class for I/O stuff. It constists of serveral static methods that perform some usefull things.
Constructor Summary | |
---|---|
IOUtilities()
|
Method Summary | |
---|---|
static void |
append(java.lang.StringBuffer buffer,
int number,
int minChars)
Appends an integer to a StringBuffer. |
static void |
clear(java.lang.StringBuffer buffer)
Clears an StringBuffer |
static void |
copy(java.io.File[] src,
java.io.File targetDir)
Copies files given in source to the target directory. |
static void |
copy(java.io.File[] src,
java.io.File targetDir,
boolean onlyNew)
Copies files given in source to the target directory. |
static void |
copy(java.io.File src,
java.io.File target)
Copies a file. |
static void |
copy(java.io.File src,
java.io.File target,
boolean onlyNew)
Copies a file. |
static java.lang.Integer[] |
decodeSingleFieldValueToMultipleEpisodeNumers(int fieldValue)
Decode the given value into an array of episode numbers. |
static java.lang.String |
decodeSingleFieldValueToMultipleEpisodeString(int fieldValue)
Decode the given value into a String of episode numbers. |
static void |
deleteDirectory(java.io.File dir)
Deletes a directory with all its files and subdirectories. |
static void |
download(java.net.URL url,
java.io.File targetFile)
Downloads a file from a HTTP server. |
static int |
encodeMultipleEpisodeNumersToSingleFieldValue(int[] episodeNumbers)
Convert an array with episode numbers into a single integer value. |
static byte[] |
getBytesFromFile(java.io.File file)
Reads all Bytes from a File into an byte array |
static int |
getMinutesAfterMidnight()
Gets the number of minutes since midnight This method does not create any objects. |
static java.io.InputStream |
getStream(java.net.URL page)
Gets an InputStream to the given URL. |
static java.io.InputStream |
getStream(java.net.URL page,
boolean followRedirects)
Gets an InputStream to the given URL. |
static java.io.InputStream |
getStream(java.net.URL page,
boolean followRedirects,
int timeout)
Originally copied from javax.swing.JEditorPane. |
static java.io.InputStream |
getStream(java.net.URL page,
boolean followRedirects,
int timeout,
java.lang.String userName,
java.lang.String userPassword)
Originally copied from javax.swing.JEditorPane. |
static java.io.InputStream |
getStream(java.net.URL page,
int timeout)
Gets an InputStream to the given URL. |
static byte[] |
loadFileFromHttpServer(java.net.URL url)
Loads a file from a Http server. |
static byte[] |
loadFileFromHttpServer(java.net.URL url,
int timeout)
Loads a file from a Http server with the given read timeout. |
static byte[] |
loadFileFromJar(java.lang.String fileName,
java.lang.Class srcClass)
Lädt eine Datei aus einem Jar-File und gibt sie zurück. |
static java.io.InputStream |
openSaveGZipInputStream(java.io.InputStream is)
This method tries to open an inputstream as gzip and uncompresses it. |
static void |
pipe(java.io.Reader reader,
java.io.Writer writer)
Pipes all data from the specified Reader to the specified Writer, until the Reader has no more data. |
static void |
pipeStreams(java.io.InputStream from,
java.io.OutputStream to)
Pipes all data from the specified InputStream to the specified OutputStream, until the InputStream has no more data. |
static byte[] |
readBinaryData(java.io.InputStream stream,
int length)
Reads a number of bytes into an array. |
static javax.swing.ImageIcon |
readImageIconFromFile(java.io.File srcFile)
Read the image from the given file to an icon image. |
static void |
replace(java.lang.StringBuffer buffer,
java.lang.String pattern,
java.lang.String str)
Replaces in buffer the pattern by str . |
static java.lang.String |
replace(java.lang.String original,
java.lang.String pattern,
java.lang.String str)
Replaces a substring in the specified String. |
static void |
saveStream(java.io.InputStream stream,
java.io.File targetFile)
Saves the data from an InputStream into a file. |
static java.lang.String |
timeToString(int minutesAfterMidnight)
Gets a String representation in the format h:mm for a time in minutes after midnight. |
static void |
ungzip(java.io.File srcFile,
java.io.File targetFile)
Unzips a GZIP-file (.gz). |
static void |
unzip(java.io.File srcFile,
java.lang.String entryName,
java.io.File targetFile)
Unzips a file from a ZIP-Archive (.zip, .jar). |
static boolean |
writeImageIconToFile(javax.swing.ImageIcon icon,
java.lang.String imageType,
java.io.File targetFile)
Writes the given image icon to the given file in the given imageType. |
static java.lang.String |
xorDecode(java.lang.String text,
long seed)
Decodes the specified String using a simple XOR encryption. |
static java.lang.String |
xorEncode(java.lang.String text,
long seed)
Encodes the specified String using a simple XOR encryption. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IOUtilities()
Method Detail |
---|
public static void download(java.net.URL url, java.io.File targetFile) throws java.io.IOException
url
- The URL of the file to download.targetFile
- The file where to store the downloaded data.
java.io.IOException
- When download or saving failed.loadFileFromHttpServer(URL)
public static void saveStream(java.io.InputStream stream, java.io.File targetFile) throws java.io.IOException
stream
- The stream to read the data from.targetFile
- The file where to store the data.
java.io.IOException
- When saving failed or when the InputStream throws an
IOException.public static java.io.InputStream getStream(java.net.URL page, boolean followRedirects) throws java.io.IOException
The connection has the Settings.propDefaultNetworkConnectionTimeout as connection timeout.
page
- The page to get the stream to.followRedirects
- If the stream should be also established if the page not exists
at the location but contains a redirect to an other location.
java.io.IOException
- Thrown if something goes wrong.public static java.io.InputStream getStream(java.net.URL page, boolean followRedirects, int timeout) throws java.io.IOException
Fetches a stream for the given URL, which is about to
be loaded by the setPage
method. By
default, this simply opens the URL and returns the
stream. This can be reimplemented to do useful things
like fetch the stream from a cache, monitor the progress
of the stream, etc.
This method is expected to have the the side effect of
establishing the content type, and therefore setting the
appropriate EditorKit
to use for loading the stream.
If this the stream was an http connection, redirects
will be followed and the resulting URL will be set as
the Document.StreamDescriptionProperty
so that relative
URL's can be properly resolved.
page
- the URL of the pagefollowRedirects
- Follow redirects.timeout
- The read timeout.
java.io.IOException
- if something went wrong.public static java.io.InputStream getStream(java.net.URL page, boolean followRedirects, int timeout, java.lang.String userName, java.lang.String userPassword) throws java.io.IOException
Fetches a stream for the given URL, which is about to
be loaded by the setPage
method. By
default, this simply opens the URL and returns the
stream. This can be reimplemented to do useful things
like fetch the stream from a cache, monitor the progress
of the stream, etc.
This method is expected to have the the side effect of
establishing the content type, and therefore setting the
appropriate EditorKit
to use for loading the stream.
If this the stream was an http connection, redirects
will be followed and the resulting URL will be set as
the Document.StreamDescriptionProperty
so that relative
URL's can be properly resolved.
page
- the URL of the pagefollowRedirects
- Follow redirects.timeout
- The read timeout.userName
- The user name to use for the connection.userPassword
- The password to use for the connection.
java.io.IOException
- if something went wrong.public static java.io.InputStream getStream(java.net.URL page) throws java.io.IOException
The connection has the Settings.propDefaultNetworkConnectionTimeout as connection timeout.
page
- The page to get the stream to.
java.io.IOException
- Thrown if something goes wrong.public static java.io.InputStream getStream(java.net.URL page, int timeout) throws java.io.IOException
The connection has the given timeout as connection timeout.
page
- The page to get the stream to.timeout
- The timeout for the connection, use 0 for no timeout.
java.io.IOException
- Thrown if something goes wrong.public static byte[] loadFileFromHttpServer(java.net.URL url) throws java.io.IOException
The connection has the Settings.propDefaultNetworkConnectionTimeout as connection timeout.
url
- The URL of the file
java.io.IOException
- When the download faileddownload(URL, File)
public static byte[] loadFileFromHttpServer(java.net.URL url, int timeout) throws java.io.IOException
url
- The URL of the filetimeout
- The read timeout for the connection.
java.io.IOException
- When the download faileddownload(URL, File)
public static void pipeStreams(java.io.InputStream from, java.io.OutputStream to) throws java.io.IOException
Note: None of the streams is closed! You have to do that for yourself!
from
- The stream to read the data from.to
- The stream to write the data to.
java.io.IOException
- Thrown if something goes wrong.public static void pipe(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Note: The Reader and the Writer are not closed! You have to do that for yourself!
reader
- The Reader to read the data from.writer
- The Writer to write the data to.
java.io.IOException
- Thrown if something goes wrong.public static void copy(java.io.File[] src, java.io.File targetDir) throws java.io.IOException
src
- The files to copy.targetDir
- The target dir of the files.
java.io.IOException
- Thrown if something goes wrong.public static void copy(java.io.File[] src, java.io.File targetDir, boolean onlyNew) throws java.io.IOException
src
- The files to copy.targetDir
- The target dir of the files.onlyNew
- Overwrite only older files.
java.io.IOException
- Thrown if something goes wrong.public static void copy(java.io.File src, java.io.File target) throws java.io.IOException
src
- The file to read fromtarget
- The file to write to
java.io.IOException
- If copying failedpublic static void copy(java.io.File src, java.io.File target, boolean onlyNew) throws java.io.IOException
src
- The file to read fromtarget
- The file to write toonlyNew
- Overwrite only older files.
java.io.IOException
- If copying failedpublic static void deleteDirectory(java.io.File dir) throws java.io.IOException
dir
- The directory to delete.
java.io.IOException
- Thrown if something goes wrong.public static byte[] loadFileFromJar(java.lang.String fileName, java.lang.Class srcClass) throws java.io.IOException
Ist keine Datei mit diesem Namen im Jar-File, so wird versucht, sie vom Dateisystem zu laden.
fileName
- Der Name der Datei. (Ist case-sensitive!).srcClass
- Eine Klasse, aus deren Jar-File das Image geladen werden soll.
java.io.IOException
- Wenn ein Fehler beim Laden der Datei auftrat.public static void unzip(java.io.File srcFile, java.lang.String entryName, java.io.File targetFile) throws java.io.IOException
Currently not used.
srcFile
- The ZIP-File to read the data from.entryName
- The name of the file in the ZIP-archive to unzip.targetFile
- The file where to store the data.
java.io.IOException
- Thrown if something goes wrong.public static void ungzip(java.io.File srcFile, java.io.File targetFile) throws java.io.IOException
srcFile
- The GZIP-File to unziptargetFile
- The file where to store the data.
java.io.IOException
- Thrown if something goes wrong.public static void append(java.lang.StringBuffer buffer, int number, int minChars)
buffer
- The buffer where to append the integer.number
- The integer to append.minChars
- The minimum number of chars.public static java.lang.String replace(java.lang.String original, java.lang.String pattern, java.lang.String str)
original
- The String to replace the substring in.pattern
- The pattern to replace.str
- The String to replace. This string may contain the pattern.
public static void replace(java.lang.StringBuffer buffer, java.lang.String pattern, java.lang.String str)
buffer
the pattern
by str
.
buffer
- The buffer to replace in.pattern
- The pattern to replace.str
- The str that should replace the pattern.public static void clear(java.lang.StringBuffer buffer)
buffer
- The buffer to clearpublic static int getMinutesAfterMidnight()
This method does not create any objects.
public static java.lang.String timeToString(int minutesAfterMidnight)
minutesAfterMidnight
- The time to get the String for
public static java.lang.String xorEncode(java.lang.String text, long seed)
text
- The text to encodeseed
- The seed of the Random object to use for getting the keys
public static java.lang.String xorDecode(java.lang.String text, long seed)
text
- The text to encodeseed
- The seed of the Random object to use for getting the keys
public static byte[] readBinaryData(java.io.InputStream stream, int length) throws java.io.IOException
stream
- The stream to read fromlength
- The number of bytes to read
java.io.IOException
- When the end of the stream has been reached or
reading failedpublic static byte[] getBytesFromFile(java.io.File file) throws java.io.IOException
file
- Read Bytes from this File
java.io.IOException
- Read-Exceptionpublic static boolean writeImageIconToFile(javax.swing.ImageIcon icon, java.lang.String imageType, java.io.File targetFile)
icon
- The icon to write.imageType
- The image type.targetFile
- The file to write the image to.
True
if the file could be written, false
if something went wrong.public static javax.swing.ImageIcon readImageIconFromFile(java.io.File srcFile)
srcFile
- The file to read from.
null
if something went wrong.public static java.io.InputStream openSaveGZipInputStream(java.io.InputStream is) throws java.io.IOException
is
- Inputstream that could be compressed
java.io.IOException
- Problems during opening of the Streampublic static int encodeMultipleEpisodeNumersToSingleFieldValue(int[] episodeNumbers) throws javax.activation.UnsupportedDataTypeException
episodeNumbers
- The array with the episode number to encode.
javax.activation.UnsupportedDataTypeException
- Is thrown if the given array didn't match the given conditions.public static java.lang.Integer[] decodeSingleFieldValueToMultipleEpisodeNumers(int fieldValue)
fieldValue
- The field value to decode.
public static java.lang.String decodeSingleFieldValueToMultipleEpisodeString(int fieldValue)
fieldValue
- The field value to decode.
|
TV-Browser 3.3.3 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |