edu.sdsc.grid.io.local
Class LocalFileOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by edu.sdsc.grid.io.GeneralFileOutputStream
          extended by edu.sdsc.grid.io.local.LocalFileOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class LocalFileOutputStream
extends GeneralFileOutputStream

A LocalFileOutputStream writes bytes to a file in a file system. What files are available depends on the host environment.

LocalFileOutputStream is meant for writing streams of raw bytes such as image data.

Basically just wraps java.io.FileOuputStream.

Since:
JARGON1.4

Field Summary
 
Fields inherited from class edu.sdsc.grid.io.GeneralFileOutputStream
fd
 
Constructor Summary
LocalFileOutputStream(LocalFile file)
          Creates a LocalFileOutputStream by opening a connection to an actual file, the file named by the LocalFile object file in the file system.
LocalFileOutputStream(java.lang.String name)
          Creates a LocalFileOutputStream by opening a connection to an actual file, the file named by the path name name in the file system.
 
Method Summary
 void close()
          Closes this file output stream and releases any system resources associated with this stream.
protected  void finalize()
          Ensures that the close method of this file input stream is called when there are no more references to it.
protected  void open(GeneralFile file)
          Opens the given file for use by this stream.
 void write(byte[] b)
          Writes b.length bytes from the specified byte array to this file output stream.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this file output stream.
 void write(int b)
          Writes the specified byte to this file output stream.
 
Methods inherited from class java.io.OutputStream
flush
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalFileOutputStream

public LocalFileOutputStream(java.lang.String name)
                      throws java.io.IOException
Creates a LocalFileOutputStream by opening a connection to an actual file, the file named by the path name name in the file system.

First, the security is checked to verify the file can be written.

If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a IOException is thrown.

Parameters:
name - the system-dependent file name.
Throws:
java.io.IOException - if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.

LocalFileOutputStream

public LocalFileOutputStream(LocalFile file)
                      throws java.io.IOException
Creates a LocalFileOutputStream by opening a connection to an actual file, the file named by the LocalFile object file in the file system. A new FileDescriptor object is created to represent this file connection.

First, the security is checked to verify the file can be written.

If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a IOException is thrown.

Parameters:
file - the file to be opened for reading.
Throws:
java.io.IOException - if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.
See Also:
File.getPath()
Method Detail

finalize

protected void finalize()
                 throws java.io.IOException
Ensures that the close method of this file input stream is called when there are no more references to it.

Overrides:
finalize in class GeneralFileOutputStream
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
edu.sdsc.grid.io.LocalFileOutputStream#close()

open

protected void open(GeneralFile file)
             throws java.io.IOException
Opens the given file for use by this stream.

Specified by:
open in class GeneralFileOutputStream
Parameters:
file - the file to be opened.
Throws:
java.io.IOException - if an I/O error occurs.

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to this file output stream. Implements the write method of OutputStream.

Overrides:
write in class GeneralFileOutputStream
Parameters:
b - the byte to be written.
Throws:
java.io.IOException - if an I/O error occurs.

write

public void write(byte[] b)
           throws java.io.IOException
Writes b.length bytes from the specified byte array to this file output stream.

Overrides:
write in class GeneralFileOutputStream
Parameters:
b - the data.
Throws:
java.io.IOException - if an I/O error occurs.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Writes len bytes from the specified byte array starting at offset off to this file output stream.

Specified by:
write in class GeneralFileOutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
java.io.IOException - if an I/O error occurs.

close

public void close()
           throws java.io.IOException
Closes this file output stream and releases any system resources associated with this stream. This file output stream may no longer be used for writing bytes.

If this stream has an associated channel then the channel is closed as well.

Specified by:
close in interface java.io.Closeable
Specified by:
close in class GeneralFileOutputStream
Throws:
java.io.IOException - if an I/O error occurs.