Added ChunkedFile interface

This commit is contained in:
Trustin Lee 2010-02-19 04:18:35 +00:00
parent c7179aa28a
commit d1c6ed6531
3 changed files with 60 additions and 20 deletions

View File

@ -0,0 +1,49 @@
/*
* Copyright 2010 Red Hat, Inc.
*
* Red Hat 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.jboss.netty.handler.stream;
import java.nio.channels.FileChannel;
/**
* A {@link ChunkedInput} that fetches data from a file chunk by chunk.
*
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
* @version $Rev: 2180 $, $Date: 2010-02-19 13:11:59 +0900 (Fri, 19 Feb 2010) $
*/
public interface ChunkedFile extends ChunkedInput {
/**
* Returns the {@link FileChannel} that this input fetches chunks from.
*/
FileChannel getSource();
/**
* Returns the offset in the file where the transfer began.
*/
long getStartOffset();
/**
* Returns the offset in the file where the transfer will end.
*/
long getEndOffset();
/**
* Returns the offset in the file where the transfer is happening currently.
*/
long getCurrentOffset();
}

View File

@ -32,7 +32,7 @@ import java.nio.channels.FileChannel;
* @author Frederic Bregier * @author Frederic Bregier
* @version $Rev$, $Date$ * @version $Rev$, $Date$
*/ */
public class ChunkedNioFile implements ChunkedInput { public class ChunkedNioFile implements ChunkedFile {
private final FileChannel in; private final FileChannel in;
private long startOffset; private long startOffset;
@ -110,23 +110,18 @@ public class ChunkedNioFile implements ChunkedInput {
endOffset = offset + length; endOffset = offset + length;
} }
/** public FileChannel getSource() {
* Returns the offset in the file where the transfer began. return in;
*/ }
public long getStartOffset() { public long getStartOffset() {
return startOffset; return startOffset;
} }
/**
* Returns the offset in the file where the transfer will end.
*/
public long getEndOffset() { public long getEndOffset() {
return endOffset; return endOffset;
} }
/**
* Returns the offset in the file where the transfer is happening currently.
*/
public long getCurrentOffset() { public long getCurrentOffset() {
return offset; return offset;
} }

View File

@ -20,6 +20,7 @@ import static org.jboss.netty.buffer.ChannelBuffers.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
/** /**
* A {@link ChunkedInput} that fetches data from a file chunk by chunk. * A {@link ChunkedInput} that fetches data from a file chunk by chunk.
@ -28,7 +29,7 @@ import java.io.RandomAccessFile;
* @author <a href="http://gleamynode.net/">Trustin Lee</a> * @author <a href="http://gleamynode.net/">Trustin Lee</a>
* @version $Rev$, $Date$ * @version $Rev$, $Date$
*/ */
public class ChunkedOioFile implements ChunkedInput { public class ChunkedOioFile implements ChunkedFile {
private final RandomAccessFile file; private final RandomAccessFile file;
private final long startOffset; private final long startOffset;
@ -104,23 +105,18 @@ public class ChunkedOioFile implements ChunkedInput {
file.seek(offset); file.seek(offset);
} }
/** public FileChannel getSource() {
* Returns the offset in the file where the transfer began. return file.getChannel();
*/ }
public long getStartOffset() { public long getStartOffset() {
return startOffset; return startOffset;
} }
/**
* Returns the offset in the file where the transfer will end.
*/
public long getEndOffset() { public long getEndOffset() {
return endOffset; return endOffset;
} }
/**
* Returns the offset in the file where the transfer is happening currently.
*/
public long getCurrentOffset() { public long getCurrentOffset() {
return offset; return offset;
} }