net.sf.cotta
Class TFile

java.lang.Object
  extended by net.sf.cotta.TEntry
      extended by net.sf.cotta.TFile
All Implemented Interfaces:
java.lang.Comparable<TEntry>

public class TFile
extends TEntry

The class that represents the file. Even though the constructor is public, the usual way is to create TFile through TFile, TDirectory, and TFileFactory

See Also:
TFileFactory.file(String), TFileFactory.fileFromJavaFile(java.io.File), TDirectory.file(String), TDirectory.file(TPath)

Field Summary
 
Fields inherited from class net.sf.cotta.TEntry
path
 
Constructor Summary
TFile(FileSystem fileSystem, TPath path)
          Deprecated. use the other constructor for default encoding support provided by factory
TFile(TFileFactory factory, TPath path)
          Create TFile instance backed up by the factory
 
Method Summary
 void append(OutputProcessor processor)
           
 java.lang.String basename()
           
 void copyTo(java.io.OutputStream outputStream)
           
 void copyTo(TFile target)
           
 TFile create()
           
 void delete()
           
 TFile ensureExists()
           
 boolean exists()
           
 java.lang.String extname()
           
 java.nio.channels.FileChannel inputChannel()
          Creates the input channel for the file
 java.io.InputStream inputStream()
          Create the input stream
 IoFactory io()
          Deprecated. use TFile itself is more effective
 long lastModified()
           
 long length()
           
 java.lang.String load()
          Load the content of the file into string using system default encoding
 void moveTo(TFile destination)
           
 void open(IoProcessor processor)
          Deprecated. use read(), write(), and append() instead
 void open(LineProcessor lineProcessor)
          Deprecated. use #read(LineProcessor)
 java.io.OutputStream outputStream(OutputMode mode)
          Create the output stream
<T> T
parse(Parser<T> parser)
          Parse the file into an object
 void read(InputProcessor processor)
          Read the file with a input processor
 void read(LineProcessor lineProcessor)
          Read the file with a line processor
 TFile save(java.lang.String content)
          Saves the content to the file
 TFile toCanonicalFile()
          Converts to the instance with a cononical path
 void write(OutputProcessor processor)
           
 
Methods inherited from class net.sf.cotta.TEntry
compareTo, equals, factory, filesystem, hashCode, isChildOf, name, parent, path, pathFrom, toCanonicalPath, toJavaFile, toPath, toPathString, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TFile

public TFile(FileSystem fileSystem,
             TPath path)
Deprecated. use the other constructor for default encoding support provided by factory

Create TFile instance backed up by the file system

Parameters:
fileSystem - file system backing the file
path - path for the file
See Also:
TFile(TFileFactory, TPath), TFile(TFileFactory, TPath)

TFile

public TFile(TFileFactory factory,
             TPath path)
Create TFile instance backed up by the factory

Parameters:
factory - file factory as the file system
path - path for the file
Method Detail

exists

public boolean exists()
Specified by:
exists in class TEntry

create

public TFile create()
             throws TIoException
Throws:
TIoException

extname

public java.lang.String extname()

basename

public java.lang.String basename()

delete

public void delete()
            throws TIoException
Throws:
TIoException

inputChannel

public java.nio.channels.FileChannel inputChannel()
                                           throws TIoException
Creates the input channel for the file

Returns:
FileChannel for input
Throws:
TIoException - error in creating the input channel

outputStream

public java.io.OutputStream outputStream(OutputMode mode)
                                  throws TIoException
Create the output stream

Parameters:
mode - output mode
Returns:
output stream for the file
Throws:
TIoException - error in creating the output stream

inputStream

public java.io.InputStream inputStream()
                                throws TIoException
Create the input stream

Returns:
input stream for the file
Throws:
TIoException - error in creating the input stream

copyTo

public void copyTo(TFile target)
            throws TIoException
Throws:
TIoException

copyTo

public void copyTo(java.io.OutputStream outputStream)
            throws TIoException
Throws:
TIoException

moveTo

public void moveTo(TFile destination)
            throws TIoException
Throws:
TIoException

length

public long length()
            throws TIoException
Throws:
TIoException

lastModified

public long lastModified()
                  throws TIoException
Throws:
TIoException

ensureExists

public TFile ensureExists()
                   throws TIoException
Throws:
TIoException

io

@Deprecated
public IoFactory io()
Deprecated. use TFile itself is more effective

Returns the IoFactory backed by the current TFile

Returns:
IoFactory
See Also:
inputChannel(), inputStream(), outputStream(net.sf.cotta.io.OutputMode)

open

@Deprecated
public void open(IoProcessor processor)
          throws TIoException
Deprecated. use read(), write(), and append() instead

Open the file for I/O processing

Parameters:
processor - processor call back
Throws:
TIoException - error in the processing
See Also:
read(net.sf.cotta.io.InputProcessor), write(net.sf.cotta.io.OutputProcessor), append(net.sf.cotta.io.OutputProcessor)

read

public void read(InputProcessor processor)
          throws TIoException
Read the file with a input processor

Parameters:
processor - processor for the input stream
Throws:
TIoException - error in reading the file

read

public void read(LineProcessor lineProcessor)
          throws TIoException
Read the file with a line processor

Parameters:
lineProcessor - line processor for the lines
Throws:
TIoException - error in reading the file

append

public void append(OutputProcessor processor)
            throws TIoException
Throws:
TIoException

write

public void write(OutputProcessor processor)
           throws TIoException
Throws:
TIoException

open

@Deprecated
public void open(LineProcessor lineProcessor)
          throws TIoException
Deprecated. use #read(LineProcessor)

Read the file with a line processor

Parameters:
lineProcessor - line processor for the lines
Throws:
TIoException - error in reading the file
See Also:
read(net.sf.cotta.io.LineProcessor)

load

public java.lang.String load()
                      throws TIoException
Load the content of the file into string using system default encoding

Returns:
content of the file
Throws:
TIoException - error in reading the file

save

public TFile save(java.lang.String content)
           throws TIoException
Saves the content to the file

Parameters:
content - content to save
Returns:
the file instance
Throws:
TIoException - if there are any exception thrown during the operation

parse

public <T> T parse(Parser<T> parser)
        throws TIoException
Parse the file into an object

Type Parameters:
T - the type of the object to return
Parameters:
parser - parser to call after opening the file for read
Returns:
the parsed object
Throws:
TIoException - error in reading the file

toCanonicalFile

public TFile toCanonicalFile()
Converts to the instance with a cononical path

Returns:
the instance with a cononical path