Author: mturk Date: Wed Aug 17 06:08:54 2011 New Revision: 1158534 URL: http://svn.apache.org/viewvc?rev=1158534&view=rev Log: Add base FilterStream class
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FilterStream.java (with props) Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FilterStream.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FilterStream.java?rev=1158534&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FilterStream.java (added) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FilterStream.java Wed Aug 17 06:08:54 2011 @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.commons.runtime.io; + +import java.io.IOException; +import java.io.SyncFailedException; +import java.nio.ByteBuffer; +import org.apache.commons.runtime.Pointer; + +/** + * Bidirectional Filter Stream. + * <p> + * This class is combination of the Java FilterInputStream and + * FilterOutputStream minus mark interface. + * </p> + */ +public abstract class FilterStream + extends Stream +{ + + /** + * Stream to be filtered. + */ + protected Stream stream; + + /** + * Creates a new object instance. + */ + protected FilterStream(Stream s) + { + stream = s; + } + + /** + * Returns the number of bytes that are available before this stream will + * block. + * This method simply performs {@code stream.available()}. + * + * @return the number of bytes available before blocking. + * @throws IOException + * if an error occurs in this stream. + * @see Stream#available() + */ + public int available() + throws IOException + { + return stream.available(); + } + + /** + * Closes the object and release any system resources it holds. If the + * object has already been closed, then invoking this method has no effect. + * This method simply performs {@code stream.close()}. + * + * @throws IOException + * if any error occurs when closing the object. + * @see Stream#close() + */ + public void close() + throws IOException + { + stream.close(); + } + + /** + * Flush the underlying stream metadata. + * This method simply performs {@code stream.available()}. + * + * @throws SyncFailedException when the object cannot be flushed. + * @throws IOException if an I/O error occurs. + * @see Stream#flush() + */ + public void flush() + throws SyncFailedException, IOException + { + stream.flush(); + } + + /** + * Sync the underlying stream by writing any buffered data. + * This method simply performs {@code stream.sync()}. + * + * @throws SyncFailedException when the object cannot be flushed. + * @throws IOException if an I/O error occurs. + * @see Stream#sync() + */ + public void sync() + throws SyncFailedException, IOException + { + stream.sync(); + } + + /** + * Test if {@code this} stream is valid. + * This method simply performs {@code stream.valid()}. + * + * @return {@code true} if the stream represents a valid, + * open file, socket, or other I/O object; {@code false} otherwse. + * + * @see Stream#valid() + */ + public boolean valid() + { + return stream.valid(); + } + + /** + * Test wather or not every I/O operation on {@code this} stream will + * block until it completes. + * This method simply performs {@code stream.isBlocking()}. + * + * @return {@code true} if, and only if, this stream + * is in blocking mode. + * + * @throws IOException if an I/O error occurs. + * @see Stream#isBlocking() + */ + public boolean isBlocking() + throws IOException + { + return stream.isBlocking(); + } + + /** + * Skips over {@code count} bytes in this stream. Less than {@code count} + * bytes are skipped if the end of the stream is reached or an exception is + * thrown during the operation. Nothing is done if {@code count} is + * negative. + * This method simply performs {@code stream.skip(count)}. + * + * @param count + * The number of bytes to skip. + * + * @return The number of bytes actually skipped. + * + * @throws ClosedDescriptorException + * If this stream is closed. + * @throws OperationWouldBlockException + * If the stream is in nonblocking mode and the operation + * would block. + * @throws OperationNotSupportedException + * If the stream is not seekable. + * @throws TimeoutException + * If operation times out. + * @throws IOException + * If some other I/O error occurs. + */ + public long skip(long count) + throws IOException + { + return stream.skip(count); + } + +} Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FilterStream.java ------------------------------------------------------------------------------ svn:eol-style = native