Package org.basex.io
Class IO
java.lang.Object
org.basex.io.IO
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-21, BSD License, Christian Gruen
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDatabase file suffix.static final intDisk block/page size (4096).static final StringCommand script suffix.static final StringCSV file suffix.static final intEntries per block (256).static final StringFile prefix.static final StringGZIP file suffix.static final String[]HTML suffixes.static final StringIgnore suffix.static final StringJAR file suffix.static final StringJSON file suffix.static final String[]JS file suffixes.protected longFile size (in bytes).static final StringXQuery log suffix.static final intMaximum number of attributes (see bit layout inDataclass).static final intTable node size power (4).static final intTable node size power (16).protected StringAbsolute file path.static final StringDirectory for raw files.static final StringTGZIP file suffix.static final StringTAR file suffix.static final StringTGZIP file suffix.static final StringTemporary file suffix.static final String[]Text suffixes.static final StringXAR file suffix.static final StringXML file suffix.static final StringXQuery module suffix.static final StringXQuery file suffix.static final String[]XQuery suffixes.static final String[]XSL suffixes.static final StringZIP file suffix.static final String[]Archive suffixes. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckSuffix(String path, String... suffixes) Tests if the file suffix of a path matches the specified suffixes.final StringdbName()Generates a database name from the name of this resource.final Stringdir()Returns the directory path (all characters up to the last slash).booleanCompares the filename of the specified IO reference.booleanexists()Tests if the reference exists.static IOReturns a class instance for the specified location string.final booleanTests if the file suffix matches the specified suffixes.abstract InputSourceReturns an input source.abstract InputStreamReturns an input stream.booleanTests if this is an absolute path.final booleanChecks if this file is an archive.booleanisDir()Tests if this is a local directory instance, or if the path ends with a slash.longlength()Returns the file length.final voidlength(long length) Sets the input length.final IOMerges two paths.final Stringname()Returns the name of the resource.final voidSets the name of the resource.final Stringpath()Returns the full path.abstract byte[]read()Returns the binary contents.abstract StreamSourceReturns a stream source.final Stringstring()Returns the contents as string.longReturns the time stamp (modification date) of this file.toString()url()Creates a URL from the specified path.
-
Field Details
-
TMPSUFFIX
Temporary file suffix.- See Also:
-
BASEXSUFFIX
Database file suffix.- See Also:
-
BXSSUFFIX
Command script suffix.- See Also:
-
XQSUFFIX
XQuery file suffix.- See Also:
-
XQMSUFFIX
XQuery module suffix.- See Also:
-
XMLSUFFIX
XML file suffix.- See Also:
-
ZIPSUFFIX
ZIP file suffix.- See Also:
-
CSVSUFFIX
CSV file suffix.- See Also:
-
JSONSUFFIX
JSON file suffix.- See Also:
-
JARSUFFIX
JAR file suffix.- See Also:
-
TARGZSUFFIX
TGZIP file suffix.- See Also:
-
TGZSUFFIX
TGZIP file suffix.- See Also:
-
GZSUFFIX
GZIP file suffix.- See Also:
-
TARSUFFIX
TAR file suffix.- See Also:
-
XARSUFFIX
XAR file suffix.- See Also:
-
LOGSUFFIX
XQuery log suffix.- See Also:
-
IGNORESUFFIX
Ignore suffix.- See Also:
-
RAW
Directory for raw files.- See Also:
-
FILEPREF
File prefix.- See Also:
-
XQSUFFIXES
XQuery suffixes. -
ZIPSUFFIXES
Archive suffixes. -
XSLSUFFIXES
XSL suffixes. -
HTMLSUFFIXES
HTML suffixes. -
TXTSUFFIXES
Text suffixes. -
JSSUFFIXES
JS file suffixes. -
BLOCKSIZE
public static final int BLOCKSIZEDisk block/page size (4096).- See Also:
-
NODEPOWER
public static final int NODEPOWERTable node size power (4).- See Also:
-
NODESIZE
public static final int NODESIZETable node size power (16).- See Also:
-
ENTRIES
public static final int ENTRIESEntries per block (256).- See Also:
-
MAXATTS
public static final int MAXATTSMaximum number of attributes (see bit layout inDataclass).- See Also:
-
pth
Absolute file path. All paths have forward slashes, no matter which OS is used. -
len
protected long lenFile size (in bytes).
-
-
Method Details
-
get
Returns a class instance for the specified location 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:
location- location- Returns:
- IO reference
-
read
Returns the binary contents.- Returns:
- binary contents
- Throws:
IOException- I/O exception
-
string
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:
IOException- I/O exception
-
exists
public boolean exists()Tests if the reference exists. Returnstruefor IO instances other thanIOFile.- Returns:
- result of check
-
isDir
public boolean isDir()Tests if this is a local directory instance, or if the path ends with a slash.- Returns:
- result of check
-
isAbsolute
public boolean isAbsolute()Tests if this is an absolute path.- Returns:
- result of check
-
hasSuffix
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 thanIOFile.- Returns:
- time stamp
-
length
public final void length(long length) Sets the input length.- Parameters:
length- length
-
length
public long length()Returns the file length.- Returns:
- file length
-
inputSource
Returns an input source.- Returns:
- input source
-
streamSource
Returns a stream source.- Returns:
- stream source
-
inputStream
Returns an input stream.- Returns:
- input stream
- Throws:
IOException- I/O exception
-
merge
Merges two paths.- Parameters:
path- path to be merged- Returns:
- resulting reference
-
isArchive
public final boolean isArchive()Checks if this file is an archive.- Returns:
- result of check
-
dbName
Generates a database name from the name of this resource. The path will be chopped and special characters from the remaining name will be removed.- Returns:
- database name
-
name
Returns the name of the resource.- Returns:
- file name
-
name
Sets the name of the resource.- Parameters:
name- file name
-
path
Returns the full path. The path uses forward slashes, no matter which OS is used.- Returns:
- path
-
dir
Returns the directory path (all characters up to the last slash). No check will be performed if the directory exists.- Returns:
- directory path
-
url
Creates a URL from the specified path. Returns the original path for IO instances other thanIOFile.- Returns:
- URL
-
eq
Compares the filename of the specified IO reference.- Parameters:
io- io reference- Returns:
- result of check
-
toString
-
checkSuffix
Tests if the file suffix of a path matches the specified suffixes.- Parameters:
path- pathsuffixes- suffixes to compare with- Returns:
- result of check
-