com.tensegrity.generic.util
Class IOUtil

java.lang.Object
  extended bycom.tensegrity.generic.util.IOUtil

public class IOUtil
extends java.lang.Object

Utility methods for IO operations

Author:
BurkhardWick

Method Summary
static java.lang.String getExtension(java.io.File f)
          Method getExtension extracts the extension of a given file.
static java.lang.String getExtension(java.lang.String filename)
          Method getExtension returns the extension of a given filename.
static java.lang.String getTextContent(java.net.URL url, java.lang.String encoding)
          Reads the contents of the file into a string and returns it.
static java.io.BufferedInputStream getUncompressedStream(java.io.File file)
          Returns a stream containing uncompressed data.
static java.io.BufferedInputStream getUncompressedStream(java.io.InputStream is)
          Returns a stream containing uncompressed data.
static boolean isCompressed(java.io.File file)
          Checks if the given file is compressed in any known format.
static boolean isCompressed(java.io.InputStream is)
          Checks if the given stream is compressed in any known format. !
static boolean isXMLFile(java.io.File file)
          Method isXMLFile reads the first line of the file and checks whether it starts with the typical xml definition.
static boolean isXMLFile(java.io.InputStream is)
          Method isXMLFile reads the first line of the file and checks whether it starts with the typical xml definition.
static java.io.File redirectWindowsLink(java.io.File linkFile)
          Tries to redirect a windows LNK file to the destination it points to
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isXMLFile

public static boolean isXMLFile(java.io.File file)
Method isXMLFile reads the first line of the file and checks whether it starts with the typical xml definition. If such a definition is found the method returns true, otherwise false.

Parameters:
file - the File to examine.
Returns:
boolean true iff the file is an xml file.

isXMLFile

public static boolean isXMLFile(java.io.InputStream is)
Method isXMLFile reads the first line of the file and checks whether it starts with the typical xml definition. If such a definition is found the method returns true, otherwise false. The stream has to support marking!

Parameters:
is - the InputStream to examine
Returns:
boolean true iff the file is an xml file.

isCompressed

public static boolean isCompressed(java.io.File file)
Checks if the given file is compressed in any known format.

Parameters:
file - The file to check
Returns:
true, if the file contains data in a known compression

isCompressed

public static boolean isCompressed(java.io.InputStream is)
Checks if the given stream is compressed in any known format. !NOTE! This method might change the position in the stream

Parameters:
is - The stream to check
Returns:
true, if the stream contains data in a known compression

getUncompressedStream

public static java.io.BufferedInputStream getUncompressedStream(java.io.File file)
                                                         throws java.io.IOException
Returns a stream containing uncompressed data.

Parameters:
file - The input file to read from
Returns:
A stream containing uncompressed data.
Throws:
java.io.IOException - If reading from the file failed

getUncompressedStream

public static java.io.BufferedInputStream getUncompressedStream(java.io.InputStream is)
                                                         throws java.io.IOException
Returns a stream containing uncompressed data.

Parameters:
is - The input stream to read from
Returns:
A stream containing uncompressed data.
Throws:
java.io.IOException - If reading from the stream failed

getExtension

public static java.lang.String getExtension(java.io.File f)
Method getExtension extracts the extension of a given file.

Parameters:
f - the file to examine.
Returns:
String the extension of the file.

getExtension

public static java.lang.String getExtension(java.lang.String filename)
Method getExtension returns the extension of a given filename.

Parameters:
filename - the name of a file as string.
Returns:
String the extension of the file or an empty string.

getTextContent

public static final java.lang.String getTextContent(java.net.URL url,
                                                    java.lang.String encoding)
                                             throws java.io.UnsupportedEncodingException,
                                                    java.io.IOException
Reads the contents of the file into a string and returns it.

Parameters:
url - The URL to read from
encoding - The encoding of the file
Returns:
The read data as string
Throws:
java.io.UnsupportedEncodingException - If the encoding is not supported
java.io.IOException - If there was an error while reading

redirectWindowsLink

public static final java.io.File redirectWindowsLink(java.io.File linkFile)
Tries to redirect a windows LNK file to the destination it points to

Parameters:
linkFile - The original file representing a LNK file
Returns:
The real file pointed to or the original file, if the link could not be resolved


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.