Top Description Inners Fields Constructors Methods
org.mortbay.util

public Class IO

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .File, .FileInputStream, .FileOutputStream, .IOException, .InputStream, .OutputStream, .Reader, .Writer, .StringWriter, .InputStreamReader, org.mortbay.log.Log, org.mortbay.thread.BoundedThreadPool, .QueuedThreadPool

IO Utilities. Provides stream handling utilities in singleton Threadpool implementation accessed by static members.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static IO.ClosedIS
private static IO.NullOS
private static IO.NullWrite
public static int
public static final String
public static final byte[]

Constructor Summary

AccessConstructor and Description
public
IO()

Method Summary

Modifier and TypeMethod and Description
public static void
close(InputStream
the input stream to close
is
)

closes an input stream, and logs exceptions

public static void
close(OutputStream
the output stream to close
os
)

closes an output stream, and logs exceptions

public static void
copy(InputStream in, OutputStream out)

Copy Stream in to Stream out until EOF or exception.

public static void
copy(Reader in, Writer out)

Copy Reader to Writer out until EOF or exception.

public static void
copy(InputStream in, OutputStream out, long byteCount)

Copy Stream in to Stream for byteCount bytes or until EOF or exception.

public static void
copy(Reader in, Writer out, long byteCount)

Copy Reader to Writer for byteCount bytes or until EOF or exception.

public static void
copy(File from, File to)

Copy files or directories

public static void
copyDir(File from, File to)

public static void
copyFile(File from, File to)

public static void
copyThread(InputStream in, OutputStream out)

Copy Stream in to Stream out until EOF or exception.

public static void
copyThread(Reader in, Writer out)

Copy Stream in to Stream out until EOF or exception in own thread

public static boolean
delete(File
The file to be deleted.
file
)

Delete File.

public static InputStream

Returns:

An outputstream to nowhere
getClosedStream
()

public static OutputStream

Returns:

An outputstream to nowhere
getNullStream
()

public static Writer

Returns:

An writer to nowhere
getNullWriter
()

public static byte[]
public static String
toString(InputStream in)

Read input stream to string.

public static String
toString(InputStream in, String encoding)

Read input stream to string.

public static String
toString(Reader in)

Read input stream to string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

__closedStreamback to summary
private static IO.ClosedIS __closedStream
__nullStreamback to summary
private static IO.NullOS __nullStream
__nullWriterback to summary
private static IO.NullWrite __nullWriter
bufferSizeback to summary
public static int bufferSize
CRLFback to summary
public static final String CRLF
CRLF_BYTESback to summary
public static final byte[] CRLF_BYTES

Constructor Detail

IOback to summary
public IO()

Method Detail

closeback to summary
public static void close(InputStream is)

closes an input stream, and logs exceptions

Parameters
is:InputStream

the input stream to close

closeback to summary
public static void close(OutputStream os)

closes an output stream, and logs exceptions

Parameters
os:OutputStream

the output stream to close

copyback to summary
public static void copy(InputStream in, OutputStream out) throws IOException

Copy Stream in to Stream out until EOF or exception.

copyback to summary
public static void copy(Reader in, Writer out) throws IOException

Copy Reader to Writer out until EOF or exception.

copyback to summary
public static void copy(InputStream in, OutputStream out, long byteCount) throws IOException

Copy Stream in to Stream for byteCount bytes or until EOF or exception.

copyback to summary
public static void copy(Reader in, Writer out, long byteCount) throws IOException

Copy Reader to Writer for byteCount bytes or until EOF or exception.

copyback to summary
public static void copy(File from, File to) throws IOException

Copy files or directories

copyDirback to summary
public static void copyDir(File from, File to) throws IOException
copyFileback to summary
public static void copyFile(File from, File to) throws IOException
copyThreadback to summary
public static void copyThread(InputStream in, OutputStream out)

Copy Stream in to Stream out until EOF or exception. in own thread

copyThreadback to summary
public static void copyThread(Reader in, Writer out)

Copy Stream in to Stream out until EOF or exception in own thread

deleteback to summary
public static boolean delete(File file)

Delete File. This delete will recursively delete directories - BE CAREFULL

Parameters
file:File

The file to be deleted.

getClosedStreamback to summary
public static InputStream getClosedStream()
Returns:InputStream

An outputstream to nowhere

getNullStreamback to summary
public static OutputStream getNullStream()
Returns:OutputStream

An outputstream to nowhere

getNullWriterback to summary
public static Writer getNullWriter()
Returns:Writer

An writer to nowhere

readBytesback to summary
public static byte[] readBytes(InputStream in) throws IOException
toStringback to summary
public static String toString(InputStream in) throws IOException

Read input stream to string.

toStringback to summary
public static String toString(InputStream in, String encoding) throws IOException

Read input stream to string.

toStringback to summary
public static String toString(Reader in) throws IOException

Read input stream to string.

org.mortbay.util back to summary

private Class IO.ClosedIS

extends InputStream
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.
Inherited from java.io.InputStream:
availableclosemarkmarkSupportednullInputStreamreadreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Constructor Detail

ClosedISback to summary
private ClosedIS()

Method Detail

readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

the next byte of data, or -1 if the end of the stream is reached.

Exceptions
IOException:
if an I/O error occurs.
org.mortbay.util back to summary

pack-priv Class IO.Job

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
pack-priv InputStream
pack-priv OutputStream
pack-priv Reader
pack-priv Writer

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
Job(Reader read, Writer write)

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

inback to summary
pack-priv InputStream in
outback to summary
pack-priv OutputStream out
readback to summary
pack-priv Reader read
writeback to summary
pack-priv Writer write

Constructor Detail

Jobback to summary
pack-priv Job(InputStream in, OutputStream out)
Jobback to summary
pack-priv Job(Reader read, Writer write)

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

org.mortbay.util back to summary

private Class IO.NullOS

extends OutputStream
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.
public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.
public void
write(byte[]
the data.
b
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.
public void
write(byte[]
the data.
b
,
int
the start offset in the data.
i
,
int
the number of bytes to write.
l
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
Inherited from java.io.OutputStream:
nullOutputStream

Constructor Detail

NullOSback to summary
private NullOS()

Method Detail

closeback to summary
public void close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

flushback to summary
public void flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

writeback to summary
public void write(byte[] b)

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Parameters
b:byte[]

the data.

writeback to summary
public void write(byte[] b, int i, int l)

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

i:int

the start offset in the data.

l:int

the number of bytes to write.

writeback to summary
public void write(int b)

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

org.mortbay.util back to summary

private Class IO.NullWrite

extends Writer
Class Inheritance

Field Summary

Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Closes the stream, flushing it first.
public void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flushes the stream.
public void
write(char[]
Array of characters to be written
b
)

Overrides java.io.Writer.write.

Writes an array of characters.
public void
write(char[]
Array of characters
b
,
int
Offset from which to start writing characters
o
,
int
Number of characters to write
l
)

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.
public void
write(int
int specifying a character to be written
b
)

Overrides java.io.Writer.write.

Writes a single character.
public void
write(String
String to be written
s
)

Overrides java.io.Writer.write.

Writes a string.
public void
write(String
A String
s
,
int
Offset from which to start writing characters
o
,
int
Number of characters to write
l
)

Overrides java.io.Writer.write.

Writes a portion of a string.
Inherited from java.io.Writer:
appendappendappendnullWriter

Constructor Detail

NullWriteback to summary
private NullWrite()

Method Detail

closeback to summary
public void close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Doc from java.io.Writer.close.

Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.

flushback to summary
public void flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Doc from java.io.Writer.flush.

Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

writeback to summary
public void write(char[] b)

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes an array of characters.

Parameters
b:char[]

Array of characters to be written

writeback to summary
public void write(char[] b, int o, int l)

Implements abstract java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of an array of characters.

Parameters
b:char[]

Array of characters

o:int

Offset from which to start writing characters

l:int

Number of characters to write

writeback to summary
public void write(int b)

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored.

Subclasses that intend to support efficient single-character output should override this method.

Parameters
b:int

int specifying a character to be written

writeback to summary
public void write(String s)

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a string.

Parameters
s:String

String to be written

writeback to summary
public void write(String s, int o, int l)

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of a string.

Parameters
s:String

A String

o:int

Offset from which to start writing characters

l:int

Number of characters to write

org.mortbay.util back to summary

private Class IO.Singleton

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final QueuedThreadPool

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

__poolback to summary
pack-priv static final QueuedThreadPool __pool

Constructor Detail

Singletonback to summary
private Singleton()