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


Java DataUtils.newBytes方法代码示例

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


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

示例1: read

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
@Override
public Object read(ByteBuffer buff, int tag) {
    switch (tag) {
    case TAG_BIG_INTEGER_0:
        return BigInteger.ZERO;
    case TAG_BIG_INTEGER_1:
        return BigInteger.ONE;
    case TAG_BIG_INTEGER_SMALL:
        return BigInteger.valueOf(DataUtils.readVarLong(buff));
    }
    int len = DataUtils.readVarInt(buff);
    byte[] bytes = DataUtils.newBytes(len);
    buff.get(bytes);
    return new BigInteger(bytes);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:16,代码来源:ObjectDataType.java

示例2: createBlob

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
 * Create a BLOB value from a stream.
 *
 * @param in the input stream
 * @param length the number of characters to read, or -1 for no limit
 * @param handler the data handler
 * @return the lob value
 */
private static ValueLob createBlob(InputStream in, long length,
        DataHandler handler) {
    try {
        if (handler == null) {
            byte[] data = IOUtils.readBytesAndClose(in, (int) length);
            return createSmallLob(Value.BLOB, data);
        }
        long remaining = Long.MAX_VALUE;
        boolean compress = handler.getLobCompressionAlgorithm(Value.BLOB) != null;
        if (length >= 0 && length < remaining) {
            remaining = length;
        }
        int len = getBufferSize(handler, compress, remaining);
        byte[] buff;
        if (len >= Integer.MAX_VALUE) {
            buff = IOUtils.readBytesAndClose(in, -1);
            len = buff.length;
        } else {
            buff = DataUtils.newBytes(len);
            len = IOUtils.readFully(in, buff, len);
        }
        if (len <= handler.getMaxLengthInplaceLob()) {
            byte[] small = DataUtils.newBytes(len);
            System.arraycopy(buff, 0, small, 0, len);
            return ValueLob.createSmallLob(Value.BLOB, small);
        }
        ValueLob lob = new ValueLob(Value.BLOB, null);
        lob.createFromStream(buff, len, in, remaining, handler);
        return lob;
    } catch (IOException e) {
        throw DbException.convertIOException(e, null);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:42,代码来源:ValueLob.java

示例3: readBytes

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
 * Read a byte array.
 *
 * @return the value
 */
public byte[] readBytes() throws IOException {
    int len = readInt();
    if (len == -1) {
        return null;
    }
    byte[] b = DataUtils.newBytes(len);
    in.readFully(b);
    return b;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:15,代码来源:Transfer.java

示例4: getBytes

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
public static byte[] getBytes(ByteBuffer bb) throws IOException {
    int len = bb.getInt();
    if (len == -1) {
        return null;
    }
    byte[] b = DataUtils.newBytes(len);
    bb.get(b);
    return b;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:10,代码来源:ByteBufferTool.java

示例5: createTempBlob

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
 * Create a temporary BLOB value from a stream.
 *
 * @param in the input stream
 * @param length the number of characters to read, or -1 for no limit
 * @param handler the data handler
 * @return the lob value
 */
public static ValueLobDb createTempBlob(InputStream in, long length,
        DataHandler handler) {
    try {
        long remaining = Long.MAX_VALUE;
        boolean compress = handler.getLobCompressionAlgorithm(Value.BLOB) != null;
        if (length >= 0 && length < remaining) {
            remaining = length;
        }
        int len = getBufferSize(handler, compress, remaining);
        byte[] buff;
        if (len >= Integer.MAX_VALUE) {
            buff = IOUtils.readBytesAndClose(in, -1);
            len = buff.length;
        } else {
            buff = DataUtils.newBytes(len);
            len = IOUtils.readFully(in, buff, len);
        }
        if (len <= handler.getMaxLengthInplaceLob()) {
            byte[] small = DataUtils.newBytes(len);
            System.arraycopy(buff, 0, small, 0, len);
            return ValueLobDb.createSmallLob(Value.BLOB, small, small.length);
        }
        ValueLobDb lob = new ValueLobDb(handler, buff, len, in, remaining);
        return lob;
    } catch (IOException e) {
        throw DbException.convertIOException(e, null);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:37,代码来源:ValueLobDb.java

示例6: uploadMultipart

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
private void uploadMultipart(InputStream in, int len) throws IOException {
    if (!new File(WebServer.TRANSFER).exists()) {
        return;
    }
    String fileName = "temp.bin";
    headerBytes = 0;
    String boundary = readHeaderLine();
    while (true) {
        String line = readHeaderLine();
        if (line == null) {
            break;
        }
        int index = line.indexOf("filename=\"");
        if (index > 0) {
            fileName = line.substring(index +
                    "filename=\"".length(), line.lastIndexOf('"'));
        }
        trace(" " + line);
    }
    if (!WebServer.isSimpleName(fileName)) {
        return;
    }
    len -= headerBytes;
    File file = new File(WebServer.TRANSFER, fileName);
    OutputStream out = new FileOutputStream(file);
    IOUtils.copy(in, out, len);
    out.close();
    // remove the boundary
    RandomAccessFile f = new RandomAccessFile(file, "rw");
    int testSize = (int) Math.min(f.length(), Constants.IO_BUFFER_SIZE);
    f.seek(f.length() - testSize);
    byte[] bytes = DataUtils.newBytes(Constants.IO_BUFFER_SIZE);
    f.readFully(bytes, 0, testSize);
    String s = new String(bytes, "ASCII");
    int x = s.lastIndexOf(boundary);
    f.setLength(f.length() - testSize + x - 2);
    f.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:39,代码来源:WebThread.java

示例7: getBuffer

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
private byte[] getBuffer(int min) {
    if (min > MAX_BUFFER_SIZE) {
        return DataUtils.newBytes(min);
    }
    if (cachedBuffer == null || cachedBuffer.length < min) {
        cachedBuffer = DataUtils.newBytes(min);
    }
    return cachedBuffer;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:10,代码来源:CompressTool.java

示例8: expand

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
/**
 * Expands the compressed  data.
 *
 * @param in the byte array with the compressed data
 * @return the uncompressed data
 */
public byte[] expand(byte[] in) {
    int algorithm = in[0];
    Compressor compress = getCompressor(algorithm);
    try {
        int len = readVariableInt(in, 1);
        int start = 1 + getVariableIntLength(len);
        byte[] buff = DataUtils.newBytes(len);
        compress.expand(in, start, in.length - start, buff, 0, len);
        return buff;
    } catch (Exception e) {
        throw DbException.get(ErrorCode.COMPRESSION_ERROR, e);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:CompressTool.java

示例9: expand

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
private void expand(int plus) {
    byte[] d = DataUtils.newBytes((data.length + plus) * 2);
    // must copy everything, because pos could be 0 and data may be
    // still required
    System.arraycopy(data, 0, d, 0, data.length);
    data = d;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:8,代码来源:Data.java

示例10: read

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
@Override
public AlleleProperties read(ByteBuffer buff) {
    int len = DataUtils.readVarInt(buff);
    byte[] data = DataUtils.newBytes(len);
    buff.get(data);
    try {
        return AlleleProperties.parseFrom(data);
    } catch (InvalidProtocolBufferException e) {
        throw new InvalidAlleleProtoException(e);
    }
}
 
开发者ID:exomiser,项目名称:Exomiser,代码行数:12,代码来源:AllelePropertiesDataType.java

示例11: read

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
@Override
public AlleleKey read(ByteBuffer buff) {
    int len = DataUtils.readVarInt(buff);
    byte[] data = DataUtils.newBytes(len);
    buff.get(data);
    try {
        return AlleleKey.parseFrom(data);
    } catch (InvalidProtocolBufferException e) {
        throw new InvalidAlleleProtoException(e);
    }
}
 
开发者ID:exomiser,项目名称:Exomiser,代码行数:12,代码来源:AlleleKeyDataType.java

示例12: ensureSize

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
private static byte[] ensureSize(byte[] buff, int len) {
    return buff == null || buff.length < len ? DataUtils.newBytes(len) : buff;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:4,代码来源:LZFInputStream.java

示例13: parseHeader

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
private boolean parseHeader() throws IOException {
    boolean keepAlive = false;
    trace("parseHeader");
    int len = 0;
    ifModifiedSince = null;
    boolean multipart = false;
    while (true) {
        String line = readHeaderLine();
        if (line == null) {
            break;
        }
        trace(" " + line);
        String lower = StringUtils.toLowerEnglish(line);
        if (lower.startsWith("if-modified-since")) {
            ifModifiedSince = getHeaderLineValue(line);
        } else if (lower.startsWith("connection")) {
            String conn = getHeaderLineValue(line);
            if ("keep-alive".equals(conn)) {
                keepAlive = true;
            }
        } else if (lower.startsWith("content-type")) {
            String type = getHeaderLineValue(line);
            if (type.startsWith("multipart/form-data")) {
                multipart = true;
            }
        } else if (lower.startsWith("content-length")) {
            len = Integer.parseInt(getHeaderLineValue(line));
            trace("len=" + len);
        } else if (lower.startsWith("user-agent")) {
            boolean isWebKit = lower.contains("webkit/");
            if (isWebKit && session != null) {
                // workaround for what seems to be a WebKit bug:
                // http://code.google.com/p/chromium/issues/detail?id=6402
                session.put("frame-border", "1");
                session.put("frameset-border", "2");
            }
        } else if (lower.startsWith("accept-language")) {
            Locale locale = session == null ? null : session.locale;
            if (locale == null) {
                String languages = getHeaderLineValue(line);
                StringTokenizer tokenizer = new StringTokenizer(languages, ",;");
                while (tokenizer.hasMoreTokens()) {
                    String token = tokenizer.nextToken();
                    if (!token.startsWith("q=")) {
                        if (server.supportsLanguage(token)) {
                            int dash = token.indexOf('-');
                            if (dash >= 0) {
                                String language = token.substring(0, dash);
                                String country = token.substring(dash + 1);
                                locale = new Locale(language, country);
                            } else {
                                locale = new Locale(token, "");
                            }
                            headerLanguage = locale.getLanguage();
                            if (session != null) {
                                session.locale = locale;
                                session.put("language", headerLanguage);
                                server.readTranslations(session, headerLanguage);
                            }
                            break;
                        }
                    }
                }
            }
        } else if (line.trim().length() == 0) {
            break;
        }
    }
    if (multipart) {
        uploadMultipart(input, len);
    } else if (session != null && len > 0) {
        byte[] bytes = DataUtils.newBytes(len);
        for (int pos = 0; pos < len;) {
            pos += input.read(bytes, pos, len - pos);
        }
        String s = new String(bytes);
        parseAttributes(s);
    }
    return keepAlive;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:81,代码来源:WebThread.java

示例14: setParameter

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
private void setParameter(PreparedStatement prep,
        int pgType, int i, int[] formatCodes) throws SQLException, IOException {
    boolean text = (i >= formatCodes.length) || (formatCodes[i] == 0);
    int col = i + 1;
    int paramLen = readInt();
    if (paramLen == -1) {
        prep.setNull(col, Types.NULL);
    } else if (text) {
        // plain text
        byte[] data = DataUtils.newBytes(paramLen);
        readFully(data);
        prep.setString(col, new String(data, getEncoding()));
    } else {
        // binary
        switch (pgType) {
        case PgServer.PG_TYPE_INT2:
            checkParamLength(4, paramLen);
            prep.setShort(col, readShort());
            break;
        case PgServer.PG_TYPE_INT4:
            checkParamLength(4, paramLen);
            prep.setInt(col, readInt());
            break;
        case PgServer.PG_TYPE_INT8:
            checkParamLength(8, paramLen);
            prep.setLong(col, dataIn.readLong());
            break;
        case PgServer.PG_TYPE_FLOAT4:
            checkParamLength(4, paramLen);
            prep.setFloat(col, dataIn.readFloat());
            break;
        case PgServer.PG_TYPE_FLOAT8:
            checkParamLength(8, paramLen);
            prep.setDouble(col, dataIn.readDouble());
            break;
        case PgServer.PG_TYPE_BYTEA:
            byte[] d1 = DataUtils.newBytes(paramLen);
            readFully(d1);
            prep.setBytes(col, d1);
            break;
        default:
            server.trace("Binary format for type: "+pgType+" is unsupported");
            byte[] d2 = DataUtils.newBytes(paramLen);
            readFully(d2);
            prep.setString(col, new String(d2, getEncoding()));
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:49,代码来源:PgServerThread.java

示例15: getPaddedArrayCopy

import org.h2.mvstore.DataUtils; //导入方法依赖的package包/类
private static byte[] getPaddedArrayCopy(byte[] data, int blockSize) {
    int size = MathUtils.roundUpInt(data.length, blockSize);
    byte[] newData = DataUtils.newBytes(size);
    System.arraycopy(data, 0, newData, 0, data.length);
    return newData;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:7,代码来源:Function.java


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