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

📄 blobinputstream.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
// $Id: BLOBInputStream.java,v 1.3 2002/12/29 11:15:55 per_nyfelt Exp $

package org.ozoneDB.blob;

import java.io.*;


/**
 * The output stream of ozone BLOBs. Every read operations will call
 * the underlaying BLOBContainer. Therefore BLOBStreams should never be used
 * without buffering/caching. This can be done by using the BLOBStream together
 * with a BufferedStream.
 * 
 * 
 * @author <a href="http://www.softwarebuero.de/">SMB</a>
 * @version $Revision: 1.3 $Date: 2002/12/29 11:15:55 $
 */
public class BLOBInputStream extends InputStream implements Serializable {
    
    BLOBContainer container;
    int index = 0;
    
    
    public BLOBInputStream( BLOBContainer _container ) {
        container = _container;
    }
    
    
    public int available() throws IOException {
        try {
            return container.available( index );
        } catch (Exception e) {
            throw new IOException( e.getMessage() );
        } 
    } 
    
    
    public boolean markSupported() {
        return false;
    } 
    
    
    public int read( byte[] b ) throws IOException {
        return read( b, 0, b.length );
    } 
    
    
    public int read( byte[] b, int off, int len ) throws IOException {
        try {
            if (b == null) {
                skip( len );
                return len;
            // but why ?!
            } 
            
            byte[] bb = container.read( index, len );
            len = bb.length;
            System.arraycopy( bb, 0, b, off, len );
            index += len;
            
            return len == 0 ? -1 : len;
        } catch (Exception e) {
            throw new IOException( e.getMessage() );
        } 
    } 
    
    
    public int read() throws IOException {
        try {
            byte[] bb = container.read( index, 1 );
            index += bb.length;
            return bb.length == 1 ? bb[0] : -1;
        } catch (Exception e) {
            throw new IOException( e.getMessage() );
        } 
    } 
    
    
    public long skip( long n ) throws IOException {
        int avail = available();
        n = Math.min( n, avail );
        index += n;
        return n;
    } 
    
    
    public void close() throws IOException {
    } 
}

⌨️ 快捷键说明

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