org.basex.io
Class IO

java.lang.Object
  extended by org.basex.io.IO
Direct Known Subclasses:
IOContent, IOFile, IOStream, IOUrl

public abstract class IO
extends java.lang.Object

Generic representation for inputs and outputs. The underlying source can be a local file (IOFile), a URL (IOUrl), a byte array (IOContent), or a stream (IOStream).

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

Field Summary
static java.lang.String BASEXSUFFIX
          Database file suffix.
static int BLOCKSIZE
          Disk block/page size (4096).
static java.lang.String BXSSUFFIX
          Command script suffix.
static java.lang.String CSVSUFFIX
          CSV file suffix.
static int ENTRIES
          Entries per block (256).
static java.lang.String FILEPREF
          File prefix.
static java.lang.String GZSUFFIX
          GZIP file suffix.
static java.lang.String[] HTMLSUFFIXES
          HTML suffixes.
static java.lang.String JARSUFFIX
          JAR file suffix.
static java.lang.String JSONSUFFIX
          JSON file suffix.
static java.lang.String LOGSUFFIX
          XQuery log suffix.
static int MAXATTS
          Maximum number of attributes (see bit layout in Data class).
static int NODEPOWER
          Table node size power (4).
static int NODESIZE
          Table node size power (16).
static long OFFCOMP
          Offset for compressing texts (see bit layout in Data class).
static long OFFNUM
          Offset for inlining numbers (see bit layout in Data class).
static java.lang.String[] TXTSUFFIXES
          Text suffixes.
static java.lang.String XARSUFFIX
          XAR file suffix.
static java.lang.String XMLSUFFIX
          XML file suffix.
static java.lang.String[] XMLSUFFIXES
          XML suffixes.
static java.lang.String XQMSUFFIX
          XQuery module suffix.
static java.lang.String XQSUFFIX
          XQuery file suffix.
static java.lang.String[] XQSUFFIXES
          XQuery suffixes.
static java.lang.String[] XSLSUFFIXES
          XML suffixes.
static java.lang.String ZIPSUFFIX
          ZIP file suffix.
static java.lang.String[] ZIPSUFFIXES
          ZIP suffixes.
 
Method Summary
 java.lang.String dbname()
          Chops the path and the file suffix of the specified filename and returns the database name.
 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.
static IO get(java.lang.String source)
          Returns a class instance for the specified string.
 boolean hasSuffix(java.lang.String... suffixes)
          Tests if the file suffix matches the specified suffixes.
abstract  org.xml.sax.InputSource inputSource()
          Returns an input source.
abstract  java.io.InputStream inputStream()
          Returns an input stream.
 boolean isArchive()
          Checks if this file is an archive.
 boolean isDir()
          Tests if this is a directory instance.
 long length()
          Returns the file length.
 void length(long l)
          Sets the input length.
 IO merge(java.lang.String in)
          Merges two paths.
 java.lang.String name()
          Returns the name of the resource.
 void name(java.lang.String n)
          Sets the name of the resource.
 java.lang.String path()
          Returns the path.
abstract  byte[] read()
          Returns the binary contents.
abstract  javax.xml.transform.stream.StreamSource streamSource()
          Returns a stream source.
 java.lang.String string()
          Returns the contents as string.
static java.lang.String suffix(java.lang.String path)
          Returns the suffix of the specified path in lower case.
 long timeStamp()
          Returns the time stamp (modification date) of this file.
 java.lang.String toString()
           
 java.lang.String url()
          Creates a URL from the specified path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BASEXSUFFIX

public static final java.lang.String BASEXSUFFIX
Database file suffix.

See Also:
Constant Field Values

BXSSUFFIX

public static final java.lang.String BXSSUFFIX
Command script suffix.

See Also:
Constant Field Values

XQSUFFIX

public static final java.lang.String XQSUFFIX
XQuery file suffix.

See Also:
Constant Field Values

XQMSUFFIX

public static final java.lang.String XQMSUFFIX
XQuery module suffix.

See Also:
Constant Field Values

XMLSUFFIX

public static final java.lang.String XMLSUFFIX
XML file suffix.

See Also:
Constant Field Values

ZIPSUFFIX

public static final java.lang.String ZIPSUFFIX
ZIP file suffix.

See Also:
Constant Field Values

CSVSUFFIX

public static final java.lang.String CSVSUFFIX
CSV file suffix.

See Also:
Constant Field Values

JSONSUFFIX

public static final java.lang.String JSONSUFFIX
JSON file suffix.

See Also:
Constant Field Values

JARSUFFIX

public static final java.lang.String JARSUFFIX
JAR file suffix.

See Also:
Constant Field Values

GZSUFFIX

public static final java.lang.String GZSUFFIX
GZIP file suffix.

See Also:
Constant Field Values

XARSUFFIX

public static final java.lang.String XARSUFFIX
XAR file suffix.

See Also:
Constant Field Values

LOGSUFFIX

public static final java.lang.String LOGSUFFIX
XQuery log suffix.

See Also:
Constant Field Values

FILEPREF

public static final java.lang.String FILEPREF
File prefix.

See Also:
Constant Field Values

XQSUFFIXES

public static final java.lang.String[] XQSUFFIXES
XQuery suffixes.


ZIPSUFFIXES

public static final java.lang.String[] ZIPSUFFIXES
ZIP suffixes.


XMLSUFFIXES

public static final java.lang.String[] XMLSUFFIXES
XML suffixes.


XSLSUFFIXES

public static final java.lang.String[] XSLSUFFIXES
XML suffixes.


HTMLSUFFIXES

public static final java.lang.String[] HTMLSUFFIXES
HTML suffixes.


TXTSUFFIXES

public static final java.lang.String[] TXTSUFFIXES
Text suffixes.


BLOCKSIZE

public static final int BLOCKSIZE
Disk block/page size (4096).

See Also:
Constant Field Values

NODEPOWER

public static final int NODEPOWER
Table node size power (4).

See Also:
Constant Field Values

NODESIZE

public static final int NODESIZE
Table node size power (16).

See Also:
Constant Field Values

ENTRIES

public static final int ENTRIES
Entries per block (256).

See Also:
Constant Field Values

MAXATTS

public static final int MAXATTS
Maximum number of attributes (see bit layout in Data class).

See Also:
Constant Field Values

OFFNUM

public static final long OFFNUM
Offset for inlining numbers (see bit layout in Data class).

See Also:
Constant Field Values

OFFCOMP

public static final long OFFCOMP
Offset for compressing texts (see bit layout in Data class).

See Also:
Constant Field Values
Method Detail

get

public static IO get(java.lang.String source)

Returns a class instance for the specified string. The type of the returned instance depends on the string value:

If the content of the string value is known in advance, it is advisable to call the direct constructors of the correspondent sub class.

Parameters:
source - source string
Returns:
IO reference

read

public abstract byte[] read()
                     throws java.io.IOException
Returns the binary contents.

Returns:
binary contents
Throws:
java.io.IOException - I/O exception

string

public final java.lang.String string()
                              throws java.io.IOException
Returns the contents as string. The input encoding will be guessed by analyzing the first bytes. UTF-8 will be used as fallback.

Returns:
string contents
Throws:
java.io.IOException - I/O exception

exists

public boolean exists()
Tests if the reference exists. Returns true for IO instances other than IOFile.

Returns:
result of check

isDir

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

Returns:
result of check

hasSuffix

public boolean hasSuffix(java.lang.String... suffixes)
Tests if the file suffix matches the specified suffixes.

Parameters:
suffixes - suffixes to compare with
Returns:
result of check

timeStamp

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

Returns:
time stamp

length

public void length(long l)
Sets the input length.

Parameters:
l - length

length

public long length()
Returns the file length.

Returns:
file length

inputSource

public abstract org.xml.sax.InputSource inputSource()
Returns an input source.

Returns:
input source

streamSource

public abstract javax.xml.transform.stream.StreamSource streamSource()
Returns a stream source.

Returns:
stream source

inputStream

public abstract java.io.InputStream inputStream()
                                         throws java.io.IOException
Returns an input stream.

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

merge

public IO merge(java.lang.String in)
Merges two paths. Returns the new specified path for IOContent and IOStream instances.

Parameters:
in - name/path to be appended
Returns:
resulting reference

isArchive

public final boolean isArchive()
Checks if this file is an archive.

Returns:
result of check

dbname

public final java.lang.String dbname()
Chops the path and the file suffix of the specified filename and returns the database name.

Returns:
database name

name

public final java.lang.String name()
Returns the name of the resource.

Returns:
file name

name

public final void name(java.lang.String n)
Sets the name of the resource.

Parameters:
n - file name

path

public final java.lang.String path()
Returns the path. The path uses forward slashes, no matter which OS is used.

Returns:
path

url

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

Returns:
URL

dirPath

public java.lang.String dirPath()
Returns the directory path.

Returns:
chopped filename

eq

public boolean eq(IO io)
Compares the filename of the specified IO reference.

Parameters:
io - io reference
Returns:
result of check

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

suffix

public static java.lang.String suffix(java.lang.String path)
Returns the suffix of the specified path in lower case. An empty string is returned if the last path segment has no suffix.

Parameters:
path - path to be checked
Returns:
mime-type