⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kfsinputstream.java

📁 nandflash文件系统源代码
💻 JAVA
字号:
/** * * Licensed 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. * * @author: Sriram Rao (Kosmix Corp.) *  * Implements the Hadoop FSInputStream interfaces to allow applications to read * files in Kosmos File System (KFS). */package org.apache.hadoop.fs.kfs;import java.io.*;import java.net.*;import java.util.*;import java.nio.ByteBuffer;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.fs.FSInputStream;import org.apache.hadoop.util.Progressable;import org.kosmix.kosmosfs.access.KfsAccess;import org.kosmix.kosmosfs.access.KfsInputChannel;class KFSInputStream extends FSInputStream {    private String path;    private KfsInputChannel kfsChannel;    private long fsize;    public KFSInputStream(KfsAccess kfsAccess, String path) {        this.path = path;        this.kfsChannel = kfsAccess.kfs_open(path);        if (this.kfsChannel != null)            this.fsize = kfsAccess.kfs_filesize(path);        else            this.fsize = 0;    }    public long getPos() throws IOException {        if (kfsChannel == null) {            throw new IOException("File closed");        }        return kfsChannel.tell();    }    public synchronized int available() throws IOException {        if (kfsChannel == null) {            throw new IOException("File closed");        }        return (int) (this.fsize - getPos());    }    public synchronized void seek(long targetPos) throws IOException {        if (kfsChannel == null) {            throw new IOException("File closed");        }        kfsChannel.seek(targetPos);    }    public synchronized boolean seekToNewSource(long targetPos) throws IOException {        return false;    }    public synchronized int read() throws IOException {        if (kfsChannel == null) {            throw new IOException("File closed");        }        byte b[] = new byte[4];        int res = read(b, 0, 1);        if (res == 1) {          return ((int) (b[0] & 0xff));        }        return -1;    }    public synchronized int read(byte b[], int off, int len) throws IOException {        if (kfsChannel == null) {            throw new IOException("File closed");        }	int res;	res = kfsChannel.read(ByteBuffer.wrap(b, off, len));	// Use -1 to signify EOF	if (res == 0)	    return -1;	return res;    }    public synchronized void close() throws IOException {        if (kfsChannel == null) {            return;        }        kfsChannel.close();        kfsChannel = null;    }    public boolean markSupported() {        return false;    }    public void mark(int readLimit) {        // Do nothing    }    public void reset() throws IOException {        throw new IOException("Mark not supported");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -