org.basex.io
Class IOFile

java.lang.Object
  extended by org.basex.io.IO
      extended by org.basex.io.IOFile

public final class IOFile
extends IO

IO reference, representing a local file or directory path.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Field Summary
 
Fields inherited from class org.basex.io.IO
BASEXSUFFIX, BLOCKSIZE, BXSSUFFIX, CSVSUFFIX, ENTRIES, FILEPREF, GZSUFFIX, HTMLSUFFIXES, JARSUFFIX, JSONSUFFIX, LOGSUFFIX, MAXATTS, NODEPOWER, NODESIZE, OFFCOMP, OFFNUM, TXTSUFFIXES, XARSUFFIX, XMLSUFFIX, XMLSUFFIXES, XQMSUFFIX, XQSUFFIX, XQSUFFIXES, XSLSUFFIXES, ZIPSUFFIX, ZIPSUFFIXES
 
Constructor Summary
IOFile(java.io.File f)
          Constructor.
IOFile(IOFile dir, java.lang.String n)
          Constructor.
IOFile(java.lang.String f)
          Constructor.
IOFile(java.lang.String dir, java.lang.String n)
          Constructor.
 
Method Summary
 IOFile[] children()
          Returns the children of the path.
 IOFile[] children(java.lang.String regex)
          Returns the children of the path that match the specified regular expression.
 void copyTo(IOFile trg)
          Copies a file to another target.
 boolean delete()
          Deletes the IO reference.
 StringList descendants()
          Returns the relative paths of all descendant files.
 IOFile dir()
          Returns a directory reference.
 java.lang.String dirPath()
          Returns the directory path.
 boolean eq(IO io)
          Compares the filename of the specified IO reference.
 boolean exists()
          Tests if the reference exists.
 java.io.File file()
          Returns the file reference.
static IOFile get(java.lang.String url)
          Normalizes the specified URL and creates a new IOFile instance.
 org.xml.sax.InputSource inputSource()
          Returns an input source.
 java.io.InputStream inputStream()
          Returns an input stream.
 boolean isDir()
          Tests if this is a directory instance.
static boolean isValid(java.lang.String s)
          Checks if the specified string is a valid file reference.
 long length()
          Returns the file length.
 boolean md()
          Recursively creates the directory.
 IO merge(java.lang.String f)
          Merges two paths.
 byte[] read()
          Returns the binary contents.
static java.lang.String regex(java.lang.String glob)
          Converts a file filter (glob) to a regular expression.
static java.lang.String regex(java.lang.String glob, boolean sub)
          Converts a file filter (glob) to a regular expression.
 boolean rename(IOFile trg)
          Renames the file to the specified name.
 javax.xml.transform.stream.StreamSource streamSource()
          Returns a stream source.
 long timeStamp()
          Returns the time stamp (modification date) of this file.
 boolean touch()
          Creates a new instance of this file.
 java.lang.String url()
          Creates a URL from the specified path.
 void write(byte[] c)
          Writes the specified byte array.
 void write(java.io.InputStream in)
          Writes the specified input.
 
Methods inherited from class org.basex.io.IO
dbname, hasSuffix, isArchive, length, name, name, path, string, suffix, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IOFile

public IOFile(java.lang.String f)
Constructor.

Parameters:
f - file path

IOFile

public IOFile(java.io.File f)
Constructor.

Parameters:
f - file reference

IOFile

public IOFile(java.lang.String dir,
              java.lang.String n)
Constructor.

Parameters:
dir - directory
n - file name

IOFile

public IOFile(IOFile dir,
              java.lang.String n)
Constructor.

Parameters:
dir - directory
n - file name
Method Detail

file

public java.io.File file()
Returns the file reference.

Returns:
file reference

touch

public boolean touch()
Creates a new instance of this file.

Returns:
success flag

read

public byte[] read()
            throws java.io.IOException
Description copied from class: IO
Returns the binary contents.

Specified by:
read in class IO
Returns:
binary contents
Throws:
java.io.IOException - I/O exception

exists

public boolean exists()
Description copied from class: IO
Tests if the reference exists. Returns true for IO instances other than IOFile.

Overrides:
exists in class IO
Returns:
result of check

isDir

public boolean isDir()
Description copied from class: IO
Tests if this is a directory instance. Returns false for IO instances other than IOFile.

Overrides:
isDir in class IO
Returns:
result of check

timeStamp

public long timeStamp()
Description copied from class: IO
Returns the time stamp (modification date) of this file. Returns the current time for IO instances other than IOFile.

Overrides:
timeStamp in class IO
Returns:
time stamp

length

public long length()
Description copied from class: IO
Returns the file length.

Overrides:
length in class IO
Returns:
file length

inputSource

public org.xml.sax.InputSource inputSource()
Description copied from class: IO
Returns an input source.

Specified by:
inputSource in class IO
Returns:
input source

streamSource

public javax.xml.transform.stream.StreamSource streamSource()
Description copied from class: IO
Returns a stream source.

Specified by:
streamSource in class IO
Returns:
stream source

inputStream

public java.io.InputStream inputStream()
                                throws java.io.IOException
Description copied from class: IO
Returns an input stream.

Specified by:
inputStream in class IO
Returns:
input stream
Throws:
java.io.IOException - I/O exception

merge

public IO merge(java.lang.String f)
Description copied from class: IO
Merges two paths. Returns the new specified path for IOContent and IOStream instances.

Overrides:
merge in class IO
Parameters:
f - name/path to be appended
Returns:
resulting reference

md

public boolean md()
Recursively creates the directory.

Returns:
success flag

dirPath

public java.lang.String dirPath()
Description copied from class: IO
Returns the directory path.

Overrides:
dirPath in class IO
Returns:
chopped filename

dir

public IOFile dir()
Returns a directory reference. If the file points to a directory, a self reference is returned

Returns:
directory

children

public IOFile[] children()
Returns the children of the path.

Returns:
children

children

public IOFile[] children(java.lang.String regex)
Returns the children of the path that match the specified regular expression.

Parameters:
regex - regular expression pattern
Returns:
children

descendants

public StringList descendants()
Returns the relative paths of all descendant files.

Returns:
relative paths

write

public void write(byte[] c)
           throws java.io.IOException
Writes the specified byte array.

Parameters:
c - contents
Throws:
java.io.IOException - I/O exception

write

public void write(java.io.InputStream in)
           throws java.io.IOException
Writes the specified input. The specified stream is eventually closed.

Parameters:
in - input stream
Throws:
java.io.IOException - I/O exception

delete

public boolean delete()
Deletes the IO reference.

Returns:
success flag

rename

public boolean rename(IOFile trg)
Renames the file to the specified name.

Parameters:
trg - target reference
Returns:
success flag

copyTo

public void copyTo(IOFile trg)
            throws java.io.IOException
Copies a file to another target.

Parameters:
trg - target
Throws:
java.io.IOException - I/O exception

eq

public boolean eq(IO io)
Description copied from class: IO
Compares the filename of the specified IO reference.

Overrides:
eq in class IO
Parameters:
io - io reference
Returns:
result of check

url

public java.lang.String url()
Description copied from class: IO
Creates a URL from the specified path. Returns the original path for IO instances other than IOFile.

Overrides:
url in class IO
Returns:
URL

isValid

public static boolean isValid(java.lang.String s)
Checks if the specified string is a valid file reference.

Parameters:
s - source
Returns:
result of check

regex

public static java.lang.String regex(java.lang.String glob)
Converts a file filter (glob) to a regular expression.

Parameters:
glob - filter
Returns:
regular expression

regex

public static java.lang.String regex(java.lang.String glob,
                                     boolean sub)
Converts a file filter (glob) to a regular expression. A filter may contain asterisks (*) and question marks (?); commas (,) are used to separate multiple filters.

Parameters:
glob - filter
sub - accept substring in the result
Returns:
regular expression

get

public static IOFile get(java.lang.String url)
Normalizes the specified URL and creates a new IOFile instance.

Parameters:
url - url to be converted
Returns:
file path