com.scudata.dm.ChannelInputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esproc Show documentation
Show all versions of esproc Show documentation
SPL(Structured Process Language) A programming language specially for structured data computing.
package com.scudata.dm;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
/**
* ??FileChannel????????????
* @author WangXiaoJun
*
*/
public class ChannelInputStream extends InputStream {
private FileChannel channel;
/**
* ????ChannelInputStream
* @param channel FileChannel
*/
public ChannelInputStream(FileChannel channel) {
this.channel = channel;
}
/**
* ֻ֧?ְ????ȡ
*/
public int read() throws IOException {
throw new IOException("read not supported");
}
/**
* b?ij??ȱ???ͻ???????????ͬ
* @param b byte[]
* @throws IOException
* @return int
*/
public int read(byte []b) throws IOException {
return read(b, 0, b.length);
}
/**
* len????ͻ???????????ͬ
* @param b byte[]
* @param off int
* @param len int
* @throws IOException
* @return int
*/
public int read(byte []b, int off, int len) throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(len);
int n = channel.read(buffer);
if (n <= 0) {
return n;
}
buffer.position(0);
buffer.get(b, off, n);
return n;
}
/**
* ????ָ?????ֽ?
* @param n ?ֽ???
*/
public long skip(long n) throws IOException {
channel.position(channel.position() + n);
return n;
}
/**
* ???ؿ??õ??ֽ???
*/
public int available() throws IOException {
return (int)(channel.size() - channel.position());
}
/**
* ?ر???????
*/
public void close() throws IOException {
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy