Renamed ChunkStream to ChunkedInput

Renamed ChunkStreamWriteHandler to ChunkedWriteHandler
Renamed FileChunkStream to ChunkedFile
This commit is contained in:
Trustin Lee 2009-06-16 08:06:00 +00:00
parent c08e7dd397
commit c2169f2b73
3 changed files with 16 additions and 16 deletions

View File

@ -33,7 +33,7 @@ import java.io.RandomAccessFile;
* @author Trustin Lee (tlee@redhat.com) * @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$ * @version $Rev$, $Date$
*/ */
public class FileChunkStream implements ChunkStream { public class ChunkedFile implements ChunkedInput {
private static final int DEFAULT_CHUNK_SIZE = 8192; private static final int DEFAULT_CHUNK_SIZE = 8192;
@ -43,19 +43,19 @@ public class FileChunkStream implements ChunkStream {
private final int chunkSize; private final int chunkSize;
private volatile long offset; private volatile long offset;
public FileChunkStream(File file) throws IOException { public ChunkedFile(File file) throws IOException {
this(file, DEFAULT_CHUNK_SIZE); this(file, DEFAULT_CHUNK_SIZE);
} }
public FileChunkStream(File file, int chunkSize) throws IOException { public ChunkedFile(File file, int chunkSize) throws IOException {
this(new RandomAccessFile(file, "r"), chunkSize); this(new RandomAccessFile(file, "r"), chunkSize);
} }
public FileChunkStream(RandomAccessFile file, int chunkSize) throws IOException { public ChunkedFile(RandomAccessFile file, int chunkSize) throws IOException {
this(file, 0, file.length(), chunkSize); this(file, 0, file.length(), chunkSize);
} }
public FileChunkStream(RandomAccessFile file, long offset, long length, int chunkSize) throws IOException { public ChunkedFile(RandomAccessFile file, long offset, long length, int chunkSize) throws IOException {
if (file == null) { if (file == null) {
throw new NullPointerException("file"); throw new NullPointerException("file");
} }

View File

@ -29,7 +29,7 @@ package org.jboss.netty.handler.stream;
* @author Trustin Lee (tlee@redhat.com) * @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$ * @version $Rev$, $Date$
*/ */
public interface ChunkStream { public interface ChunkedInput {
boolean available() throws Exception; boolean available() throws Exception;
Object readChunk() throws Exception; Object readChunk() throws Exception;
void close() throws Exception; void close() throws Exception;

View File

@ -48,10 +48,10 @@ import org.jboss.netty.util.internal.LinkedTransferQueue;
* @version $Rev$, $Date$ * @version $Rev$, $Date$
*/ */
@ChannelPipelineCoverage("one") @ChannelPipelineCoverage("one")
public class ChunkStreamWriteHandler implements ChannelUpstreamHandler, ChannelDownstreamHandler { public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDownstreamHandler {
private static final InternalLogger logger = private static final InternalLogger logger =
InternalLoggerFactory.getInstance(ChunkStreamWriteHandler.class); InternalLoggerFactory.getInstance(ChunkedWriteHandler.class);
private final Queue<MessageEvent> queue = private final Queue<MessageEvent> queue =
new LinkedTransferQueue<MessageEvent>(); new LinkedTransferQueue<MessageEvent>();
@ -101,20 +101,20 @@ public class ChunkStreamWriteHandler implements ChannelUpstreamHandler, ChannelD
} }
Object m = currentEvent.getMessage(); Object m = currentEvent.getMessage();
if (m instanceof ChunkStream) { if (m instanceof ChunkedInput) {
ChunkStream stream = (ChunkStream) m; ChunkedInput chunks = (ChunkedInput) m;
Object chunk; Object chunk;
boolean last; boolean last;
try { try {
chunk = stream.readChunk(); chunk = chunks.readChunk();
last = !stream.available(); last = !chunks.available();
} catch (Throwable t) { } catch (Throwable t) {
currentEvent.getFuture().setFailure(t); currentEvent.getFuture().setFailure(t);
fireExceptionCaught(ctx, t); fireExceptionCaught(ctx, t);
try { try {
stream.close(); chunks.close();
} catch (Throwable t2) { } catch (Throwable t2) {
logger.warn("Failed to close a stream.", t2); logger.warn("Failed to close a chunked input.", t2);
} }
break; break;
} }
@ -128,7 +128,7 @@ public class ChunkStreamWriteHandler implements ChannelUpstreamHandler, ChannelD
writeFuture.addListener(new ChannelFutureListener() { writeFuture.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) public void operationComplete(ChannelFuture future)
throws Exception { throws Exception {
((ChunkStream) currentEvent.getMessage()).close(); ((ChunkedInput) currentEvent.getMessage()).close();
} }
}); });
@ -139,7 +139,7 @@ public class ChunkStreamWriteHandler implements ChannelUpstreamHandler, ChannelD
throws Exception { throws Exception {
if (!future.isSuccess()) { if (!future.isSuccess()) {
currentEvent.getFuture().setFailure(future.getCause()); currentEvent.getFuture().setFailure(future.getCause());
((ChunkStream) currentEvent.getMessage()).close(); ((ChunkedInput) currentEvent.getMessage()).close();
} }
} }
}); });