public class IOUtilities extends Object
Constructor and Description |
---|
IOUtilities() |
Modifier and Type | Method and Description |
---|---|
static void |
append(StringBuffer buffer,
int number,
int minChars)
Appends an integer to a StringBuffer.
|
static void |
clear(StringBuffer buffer)
Clears an StringBuffer
|
static void |
copy(File[] src,
File targetDir)
Copies files given in source to the target directory.
|
static void |
copy(File[] src,
File targetDir,
boolean onlyNew)
Copies files given in source to the target directory.
|
static void |
copy(File src,
File target)
Copies a file.
|
static void |
copy(File src,
File target,
boolean onlyNew)
Copies a file.
|
static void |
deleteDirectory(File dir)
Deletes a directory with all its files and subdirectories.
|
static void |
download(URL url,
File targetFile)
Downloads a file from a HTTP server.
|
static byte[] |
getBytesFromFile(File file)
Reads all Bytes from a File into an byte array
|
static int |
getDaysSince1970()
Deprecated.
|
static int |
getMinutesAfterMidnight()
Gets the number of minutes since midnight
This method does not create any objects.
|
static InputStream |
getStream(URL page)
Gets an InputStream to the given URL.
|
static InputStream |
getStream(URL page,
boolean followRedirects)
Gets an InputStream to the given URL.
|
static InputStream |
getStream(URL page,
boolean followRedirects,
int timeout)
Originally copied from javax.swing.JEditorPane.
|
static InputStream |
getStream(URL page,
boolean followRedirects,
int timeout,
String userName,
String userPassword)
Originally copied from javax.swing.JEditorPane.
|
static InputStream |
getStream(URL page,
int timeout)
Gets an InputStream to the given URL.
|
static byte[] |
loadFileFromHttpServer(URL url)
Loads a file from a Http server.
|
static byte[] |
loadFileFromHttpServer(URL url,
int timeout)
Loads a file from a Http server with the given
read timeout.
|
static byte[] |
loadFileFromJar(String fileName,
Class srcClass)
L�dt eine Datei aus einem Jar-File und gibt sie zur�ck.
|
static void |
pipe(Reader reader,
Writer writer)
Pipes all data from the specified Reader to the specified Writer,
until the Reader has no more data.
|
static void |
pipeStreams(InputStream from,
OutputStream to)
Pipes all data from the specified InputStream to the specified OutputStream,
until the InputStream has no more data.
|
static byte[] |
readBinaryData(InputStream stream,
int length)
Reads a number of bytes into an array.
|
static ImageIcon |
readImageIconFromFile(File srcFile)
Read the image from the given file to an icon image.
|
static void |
replace(StringBuffer buffer,
String pattern,
String str)
Replaces in
buffer the pattern by str . |
static String |
replace(String original,
String pattern,
String str)
Replaces a substring in the specified String.
|
static void |
saveStream(InputStream stream,
File targetFile)
Saves the data from an InputStream into a file.
|
static String |
timeToString(int minutesAfterMidnight)
Gets a String representation in the format h:mm for a time in minutes after
midnight.
|
static void |
ungzip(File srcFile,
File targetFile)
Unzips a GZIP-file (.gz).
|
static void |
unzip(File srcFile,
String entryName,
File targetFile)
Unzips a file from a ZIP-Archive (.zip, .jar).
|
static boolean |
writeImageIconToFile(ImageIcon icon,
String imageType,
File targetFile)
Writes the given image icon to the given file in the given imageType.
|
static String |
xorDecode(String text,
long seed)
Decodes the specified String using a simple XOR encryption.
|
static String |
xorEncode(String text,
long seed)
Encodes the specified String using a simple XOR encryption.
|
public static void download(URL url, File targetFile) throws IOException
url
- The URL of the file to download.targetFile
- The file where to store the downloaded data.IOException
- When download or saving failed.loadFileFromHttpServer(URL)
public static void saveStream(InputStream stream, File targetFile) throws IOException
stream
- The stream to read the data from.targetFile
- The file where to store the data.IOException
- When saving failed or when the InputStream throws an
IOException.public static InputStream getStream(URL page, boolean followRedirects) throws 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.IOException
- Thrown if something goes wrong.public static InputStream getStream(URL page, boolean followRedirects, int timeout) throws 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.IOException
- if something went wrong.public static InputStream getStream(URL page, boolean followRedirects, int timeout, String userName, String userPassword) throws 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.IOException
- if something went wrong.public static InputStream getStream(URL page) throws IOException
The connection has the Settings.propDefaultNetworkConnectionTimeout as connection timeout.
page
- The page to get the stream to.IOException
- Thrown if something goes wrong.public static InputStream getStream(URL page, int timeout) throws 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.IOException
- Thrown if something goes wrong.public static byte[] loadFileFromHttpServer(URL url) throws IOException
The connection has the Settings.propDefaultNetworkConnectionTimeout as connection timeout.
url
- The URL of the fileIOException
- When the download faileddownload(URL, File)
public static byte[] loadFileFromHttpServer(URL url, int timeout) throws IOException
url
- The URL of the filetimeout
- The read timeout for the connection.IOException
- When the download faileddownload(URL, File)
public static void pipeStreams(InputStream from, OutputStream to) throws 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.IOException
- Thrown if something goes wrong.public static void pipe(Reader reader, Writer writer) throws 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.IOException
- Thrown if something goes wrong.public static void copy(File[] src, File targetDir) throws IOException
src
- The files to copy.targetDir
- The target dir of the files.IOException
- Thrown if something goes wrong.public static void copy(File[] src, File targetDir, boolean onlyNew) throws IOException
src
- The files to copy.targetDir
- The target dir of the files.onlyNew
- Overwrite only older files.IOException
- Thrown if something goes wrong.public static void copy(File src, File target) throws IOException
src
- The file to read fromtarget
- The file to write toIOException
- If copying failedpublic static void copy(File src, File target, boolean onlyNew) throws IOException
src
- The file to read fromtarget
- The file to write toonlyNew
- Overwrite only older files.IOException
- If copying failedpublic static void deleteDirectory(File dir) throws IOException
dir
- The directory to delete.IOException
- Thrown if something goes wrong.public static byte[] loadFileFromJar(String fileName, Class srcClass) throws 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.IOException
- Wenn ein Fehler beim Laden der Datei auftrat.public static void unzip(File srcFile, String entryName, File targetFile) throws 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.IOException
- Thrown if something goes wrong.public static void ungzip(File srcFile, File targetFile) throws IOException
srcFile
- The GZIP-File to unziptargetFile
- The file where to store the data.IOException
- Thrown if something goes wrong.public static void append(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 String replace(String original, String pattern, 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(StringBuffer buffer, String pattern, 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(StringBuffer buffer)
buffer
- The buffer to clearpublic static int getMinutesAfterMidnight()
This method does not create any objects.
public static String timeToString(int minutesAfterMidnight)
minutesAfterMidnight
- The time to get the String forpublic static int getDaysSince1970()
This method does not create any objects.
public static String xorEncode(String text, long seed)
text
- The text to encodeseed
- The seed of the Random object to use for getting the keyspublic static String xorDecode(String text, long seed)
text
- The text to encodeseed
- The seed of the Random object to use for getting the keyspublic static byte[] readBinaryData(InputStream stream, int length) throws IOException
stream
- The stream to read fromlength
- The number of bytes to readIOException
- When the end of the stream has been reached or
reading failedpublic static byte[] getBytesFromFile(File file) throws IOException
file
- Read Bytes from this FileIOException
- Read-Exceptionpublic static boolean writeImageIconToFile(ImageIcon icon, String imageType, 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.TV-Browser 2.7.6, Copyright (C) 04-2003 Martin Oberhauser (martin@tvbrowser.org)