br.com.objectos.fs
Interface RegularFile

All Superinterfaces:
InputStreamSource, OutputStreamSource, PathName, ReaderSource, WritablePathName, WriterSource

public interface RegularFile
extends PathName, InputStreamSource, ReaderSource, WritablePathName

A façade for regular file only operations.

This is only a façade. More specifically, the underlying object may or may not represent an actual regular file. For example, the file may have been deleted between the time an instance of this interface is obtained and the time a method in this interface is invoked.

This interface can be used as both the source and destination in methods from the Copy, Read and Write classes.

Since:
2
See Also:
Copy, Read, Write

Method Summary
<R,P> R
acceptPathNameVisitor(PathNameVisitor<R,P> visitor, P p)
          Accept method used to implement the visitor pattern.
 void delete()
          Deletes this file.
 boolean exists()
          Returns true if the pathname represented by this object exists.
 long getLastModifiedMillis()
          Returns the last modification time in millis.
 String getName()
          Returns the name of this file.
 Directory getParent()
          Returns the parent of this object.
 String getPath()
          Returns the full path of this object.
 boolean is(RegularFileIsOption attribute)
          Tests if this file has the specified attribute.
 InputStream openInputStream()
          Returns a new input stream for reading from this file.
 OutputStream openOutputStream()
          Returns a new output stream, in append mode, for writing to this file.
 FileChannel openReadAndWriteChannel()
          Returns a new channel for reading from and writing to this file.
 FileChannel openReadChannel()
          Returns a new channel for reading from this file.
 long size()
          Returns the file size in number of bytes.
 File toFile()
          Returns a File representation of this file.
 URI toUri()
          Returns an URI representation of this pathname.
 void truncate()
          Truncates this file.
 
Methods inherited from interface br.com.objectos.core.io.ReaderSource
openReader
 
Methods inherited from interface br.com.objectos.fs.WritablePathName
openWriteChannel, openWriter
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface br.com.objectos.core.object.ToStringObject
formatToString
 

Method Detail

delete

void delete()
            throws IOException
Deletes this file.

Throws:
IOException - if an I/O error occurs

getLastModifiedMillis

long getLastModifiedMillis()
                           throws IOException
Returns the last modification time in millis.

Returns:
the last modification time in millis.
Throws:
IOException - if an I/O error occurs

getName

String getName()
Returns the name of this file.

Returns:
the name of this file

getParent

Directory getParent()
                    throws NotFoundException
Returns the parent of this object.

If this object represents a nonexistent pathname then its parent might also be nonexistent.

Returns:
the parent of this object
Throws:
NotFoundException - if a parent for this object cannot be found

is

boolean is(RegularFileIsOption attribute)
           throws IOException
Tests if this file has the specified attribute.

Parameters:
attribute - the attribute to check for
Returns:
true if this file has the specified attribute
Throws:
IOException - if an I/O error occurs

openInputStream

InputStream openInputStream()
                            throws IOException
Returns a new input stream for reading from this file.

Specified by:
openInputStream in interface InputStreamSource
Returns:
a new input stream for reading from this file
Throws:
IOException - if an I/O error occurs

openOutputStream

OutputStream openOutputStream()
                              throws IOException
Returns a new output stream, in append mode, for writing to this file.

Specified by:
openOutputStream in interface OutputStreamSource
Specified by:
openOutputStream in interface WritablePathName
Returns:
a new output stream, in append mode, for writing to this file
Throws:
IOException - if an I/O error occurs
See Also:
truncate()

openReadAndWriteChannel

FileChannel openReadAndWriteChannel()
                                    throws IOException
Returns a new channel for reading from and writing to this file.

The returned channel is open in read and write mode and its initial position is 0L.

Returns:
a new channel for reading from and writing to this file. The returned channel is open in read and write mode and its initial position is 0L
Throws:
IOException - if an I/O error occurs

openReadChannel

FileChannel openReadChannel()
                            throws IOException
Returns a new channel for reading from this file.

The returned channel is open in read-only mode and its initial position is 0L.

Returns:
a new channel for reading from this file. The returned channel is open in read-only mode and its initial position is 0L
Throws:
IOException - if an I/O error occurs

size

long size()
          throws IOException
Returns the file size in number of bytes.

Returns:
the file size in number of bytes
Throws:
IOException - if an I/O error occurs

toFile

File toFile()
Returns a File representation of this file.

Returns:
a File representation of this file

truncate

void truncate()
              throws IOException
Truncates this file. The size of this file will be zero after this method returns.

Throws:
IOException - if an I/O error occurs

acceptPathNameVisitor

<R,P> R acceptPathNameVisitor(PathNameVisitor<R,P> visitor,
                              P p)
                        throws IOException
Accept method used to implement the visitor pattern.

Type Parameters:
R - the result type of this operation
P - the type of the additional object
Parameters:
visitor - the visitor operating on this PathName instance
p - additional object passed to the visitor
Returns:
the value returned from the visitor method
Throws:
IOException - if an I/O error occurs

exists

boolean exists()
Returns true if the pathname represented by this object exists.

Returns:
true if the pathname represented by this object exists

getPath

String getPath()
Returns the full path of this object.

Returns:
the full path of this object

toUri

URI toUri()
Returns an URI representation of this pathname.

Returns:
an URI representation of this pathname


Copyright © 2021 Objectos Software LTDA. All rights reserved.