当前位置: 首页>>代码示例>>Java>>正文


Java IOUtils.skipFully方法代码示例

本文整理汇总了Java中org.h2.util.IOUtils.skipFully方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.skipFully方法的具体用法?Java IOUtils.skipFully怎么用?Java IOUtils.skipFully使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.h2.util.IOUtils的用法示例。


在下文中一共展示了IOUtils.skipFully方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBytes

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Returns some bytes of the object.
 *
 * @param pos the index, the first byte is at position 1
 * @param length the number of bytes
 * @return the bytes, at most length bytes
 */
@Override
public byte[] getBytes(long pos, int length) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("getBytes("+pos+", "+length+");");
        }
        checkClosed();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        InputStream in = value.getInputStream();
        try {
            IOUtils.skipFully(in, pos - 1);
            IOUtils.copy(in, out, length);
        } finally {
            in.close();
        }
        return out.toByteArray();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:28,代码来源:JdbcBlob.java

示例2: getSubString

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Returns a substring.
 *
 * @param pos the position (the first character is at position 1)
 * @param length the number of characters
 * @return the string
 */
@Override
public String getSubString(long pos, int length) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("getSubString(" + pos + ", " + length + ");");
        }
        checkClosed();
        if (pos < 1) {
            throw DbException.getInvalidValueException("pos", pos);
        }
        if (length < 0) {
            throw DbException.getInvalidValueException("length", length);
        }
        StringWriter writer = new StringWriter(
                Math.min(Constants.IO_BUFFER_SIZE, length));
        Reader reader = value.getReader();
        try {
            IOUtils.skipFully(reader, pos - 1);
            IOUtils.copyAndCloseInput(reader, writer, length);
        } finally {
            reader.close();
        }
        return writer.toString();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:35,代码来源:JdbcClob.java

示例3: seek

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void seek() throws IOException {
    if (inPos > pos) {
        if (in != null) {
            in.close();
        }
        in = null;
    }
    if (in == null) {
        in = file.getInputStream(entry);
        inPos = 0;
    }
    if (inPos < pos) {
        long skip = pos - inPos;
        if (!skipUsingRead) {
            try {
                IOUtils.skipFully(in, skip);
            } catch (NullPointerException e) {
                // workaround for Android
                skipUsingRead = true;
            }
        }
        if (skipUsingRead) {
            while (skip > 0) {
                int s = (int) Math.min(SKIP_BUFFER.length, skip);
                s = in.read(SKIP_BUFFER, 0, s);
                skip -= s;
            }
        }
        inPos = pos;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:32,代码来源:FilePathZip.java

示例4: send

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Send a file to the client. This method waits until the client has
 * connected.
 *
 * @param fileName the source file name
 * @param skip the number of bytes to skip
 */
synchronized void send(String fileName, long skip) throws IOException {
    connect();
    try {
        OutputStream out = socket.getOutputStream();
        InputStream in = FileUtils.newInputStream(fileName);
        IOUtils.skipFully(in, skip);
        IOUtils.copy(in, out);
        in.close();
    } finally {
        socket.close();
    }
    server.trace("closed");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:FtpData.java

示例5: seek

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void seek() throws IOException {
    if (inPos > pos) {
        if (in != null) {
            in.close();
        }
        in = null;
    }
    if (in == null) {
        in = FileUtils.newInputStream(fullName);
        inPos = 0;
    }
    if (inPos < pos) {
        long skip = pos - inPos;
        if (!skipUsingRead) {
            try {
                IOUtils.skipFully(in, skip);
            } catch (NullPointerException e) {
                // workaround for Android
                skipUsingRead = true;
            }
        }
        if (skipUsingRead) {
            while (skip > 0) {
                int s = (int) Math.min(SKIP_BUFFER.length, skip);
                s = in.read(SKIP_BUFFER, 0, s);
                skip -= s;
            }
        }
        inPos = pos;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:32,代码来源:FilePathZip2.java

示例6: position

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * [Not supported] Searches a pattern and return the position.
 *
 * @param pattern the pattern to search
 * @param start the index, the first byte is at position 1
 * @return the position (first byte is at position 1), or -1 for not found
 */
@Override
public long position(byte[] pattern, long start) throws SQLException {
    if (isDebugEnabled()) {
        debugCode("position("+quoteBytes(pattern)+", "+start+");");
    }
    if (Constants.BLOB_SEARCH) {
        try {
            checkClosed();
            if (pattern == null) {
                return -1;
            }
            if (pattern.length == 0) {
                return 1;
            }
            // TODO performance: blob pattern search is slow
            BufferedInputStream in = new BufferedInputStream(value.getInputStream());
            IOUtils.skipFully(in, start - 1);
            int pos = 0;
            int patternPos = 0;
            while (true) {
                int x = in.read();
                if (x < 0) {
                    break;
                }
                if (x == (pattern[patternPos] & 0xff)) {
                    if (patternPos == 0) {
                        in.mark(pattern.length);
                    }
                    if (patternPos == pattern.length) {
                        return pos - patternPos;
                    }
                    patternPos++;
                } else {
                    if (patternPos > 0) {
                        in.reset();
                        pos -= patternPos;
                    }
                }
                pos++;
            }
            return -1;
        } catch (Exception e) {
            throw logAndConvert(e);
        }
    }
    throw unsupported("LOB search");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:55,代码来源:JdbcBlob.java


注:本文中的org.h2.util.IOUtils.skipFully方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。