Renamed ChunkStream to ChunkedInput
Renamed ChunkStreamWriteHandler to ChunkedWriteHandler Renamed FileChunkStream to ChunkedFile
This commit is contained in:
parent
c08e7dd397
commit
c2169f2b73
@ -33,7 +33,7 @@ import java.io.RandomAccessFile;
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class FileChunkStream implements ChunkStream {
|
||||
public class ChunkedFile implements ChunkedInput {
|
||||
|
||||
private static final int DEFAULT_CHUNK_SIZE = 8192;
|
||||
|
||||
@ -43,19 +43,19 @@ public class FileChunkStream implements ChunkStream {
|
||||
private final int chunkSize;
|
||||
private volatile long offset;
|
||||
|
||||
public FileChunkStream(File file) throws IOException {
|
||||
public ChunkedFile(File file) throws IOException {
|
||||
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);
|
||||
}
|
||||
|
||||
public FileChunkStream(RandomAccessFile file, int chunkSize) throws IOException {
|
||||
public ChunkedFile(RandomAccessFile file, int chunkSize) throws IOException {
|
||||
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) {
|
||||
throw new NullPointerException("file");
|
||||
}
|
@ -29,7 +29,7 @@ package org.jboss.netty.handler.stream;
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public interface ChunkStream {
|
||||
public interface ChunkedInput {
|
||||
boolean available() throws Exception;
|
||||
Object readChunk() throws Exception;
|
||||
void close() throws Exception;
|
@ -48,10 +48,10 @@ import org.jboss.netty.util.internal.LinkedTransferQueue;
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
@ChannelPipelineCoverage("one")
|
||||
public class ChunkStreamWriteHandler implements ChannelUpstreamHandler, ChannelDownstreamHandler {
|
||||
public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDownstreamHandler {
|
||||
|
||||
private static final InternalLogger logger =
|
||||
InternalLoggerFactory.getInstance(ChunkStreamWriteHandler.class);
|
||||
InternalLoggerFactory.getInstance(ChunkedWriteHandler.class);
|
||||
|
||||
private final Queue<MessageEvent> queue =
|
||||
new LinkedTransferQueue<MessageEvent>();
|
||||
@ -101,20 +101,20 @@ public class ChunkStreamWriteHandler implements ChannelUpstreamHandler, ChannelD
|
||||
}
|
||||
|
||||
Object m = currentEvent.getMessage();
|
||||
if (m instanceof ChunkStream) {
|
||||
ChunkStream stream = (ChunkStream) m;
|
||||
if (m instanceof ChunkedInput) {
|
||||
ChunkedInput chunks = (ChunkedInput) m;
|
||||
Object chunk;
|
||||
boolean last;
|
||||
try {
|
||||
chunk = stream.readChunk();
|
||||
last = !stream.available();
|
||||
chunk = chunks.readChunk();
|
||||
last = !chunks.available();
|
||||
} catch (Throwable t) {
|
||||
currentEvent.getFuture().setFailure(t);
|
||||
fireExceptionCaught(ctx, t);
|
||||
try {
|
||||
stream.close();
|
||||
chunks.close();
|
||||
} catch (Throwable t2) {
|
||||
logger.warn("Failed to close a stream.", t2);
|
||||
logger.warn("Failed to close a chunked input.", t2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -128,7 +128,7 @@ public class ChunkStreamWriteHandler implements ChannelUpstreamHandler, ChannelD
|
||||
writeFuture.addListener(new ChannelFutureListener() {
|
||||
public void operationComplete(ChannelFuture future)
|
||||
throws Exception {
|
||||
((ChunkStream) currentEvent.getMessage()).close();
|
||||
((ChunkedInput) currentEvent.getMessage()).close();
|
||||
}
|
||||
});
|
||||
|
||||
@ -139,7 +139,7 @@ public class ChunkStreamWriteHandler implements ChannelUpstreamHandler, ChannelD
|
||||
throws Exception {
|
||||
if (!future.isSuccess()) {
|
||||
currentEvent.getFuture().setFailure(future.getCause());
|
||||
((ChunkStream) currentEvent.getMessage()).close();
|
||||
((ChunkedInput) currentEvent.getMessage()).close();
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user