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


Java IOUtils.readBytesAndClose方法代码示例

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


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

示例1: getString

import org.h2.util.IOUtils; //导入方法依赖的package包/类
@Override
public String getString() {
    int len = precision > Integer.MAX_VALUE || precision == 0 ?
            Integer.MAX_VALUE : (int) precision;
    try {
        if (type == Value.CLOB) {
            if (small != null) {
                return new String(small, Constants.UTF8);
            }
            return IOUtils.readStringAndClose(getReader(), len);
        }
        byte[] buff;
        if (small != null) {
            buff = small;
        } else {
            buff = IOUtils.readBytesAndClose(getInputStream(), len);
        }
        return StringUtils.convertBytesToHex(buff);
    } catch (IOException e) {
        throw DbException.convertIOException(e, fileName);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:ValueLob.java

示例2: getBytesNoCopy

import org.h2.util.IOUtils; //导入方法依赖的package包/类
@Override
public byte[] getBytesNoCopy() {
    if (type == CLOB) {
        // convert hex to string
        return super.getBytesNoCopy();
    }
    if (small != null) {
        return small;
    }
    try {
        return IOUtils.readBytesAndClose(
                getInputStream(), Integer.MAX_VALUE);
    } catch (IOException e) {
        throw DbException.convertIOException(e, fileName);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:ValueLob.java

示例3: getString

import org.h2.util.IOUtils; //导入方法依赖的package包/类
@Override
public String getString() {
    int len = precision > Integer.MAX_VALUE || precision == 0 ?
            Integer.MAX_VALUE : (int) precision;
    try {
        if (type == Value.CLOB) {
            if (small != null) {
                return new String(small, Constants.UTF8);
            }
            return IOUtils.readStringAndClose(getReader(), len);
        }
        byte[] buff;
        if (small != null) {
            buff = small;
        } else {
            buff = IOUtils.readBytesAndClose(getInputStream(), len);
        }
        return StringUtils.convertBytesToHex(buff);
    } catch (IOException e) {
        throw DbException.convertIOException(e, toString());
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:ValueLobDb.java

示例4: getFile

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Read the given file from the file system or from the resources.
 *
 * @param file the file name
 * @return the data
 */
byte[] getFile(String file) throws IOException {
    trace("getFile <" + file + ">");
    if (file.startsWith(TRANSFER + "/") && new File(TRANSFER).exists()) {
        file = file.substring(TRANSFER.length() + 1);
        if (!isSimpleName(file)) {
            return null;
        }
        File f = new File(TRANSFER, file);
        if (!f.exists()) {
            return null;
        }
        return IOUtils.readBytesAndClose(new FileInputStream(f), -1);
    }
    byte[] data = Utils.getResource("/org/h2/server/web/res/" + file);
    if (data == null) {
        trace(" null");
    } else {
        trace(" size=" + data.length);
    }
    return data;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:28,代码来源:WebServer.java

示例5: processHtml

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void processHtml(String fileName) throws Exception {
    String source = "src/tools/org/h2/jcr/";
    String target = "docs/html/";
    byte[] s = BuildBase.readFile(new File(source + "stylesheet.css"));
    BuildBase.writeFile(new File(target + "stylesheet.css"), s);
    String inFile = source + fileName;
    String outFile = target + fileName;
    new File(outFile).getParentFile().mkdirs();
    FileOutputStream out = new FileOutputStream(outFile);
    FileInputStream in = new FileInputStream(inFile);
    byte[] bytes = IOUtils.readBytesAndClose(in, 0);
    if (fileName.endsWith(".html")) {
        String page = new String(bytes);
        page = PageParser.parse(page, session);
        bytes = page.getBytes();
    }
    out.write(bytes);
    out.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:Railroads.java

示例6: addFiles

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private static void addFiles(File base, File file, ZipOutputStream out)
        throws IOException {
    if (file.isDirectory()) {
        for (File f : file.listFiles()) {
            addFiles(base, f, out);
        }
    } else {
        String path = file.getAbsolutePath().substring(base.getAbsolutePath().length());
        path = path.replace('\\', '/');
        if (path.startsWith("/")) {
            path = path.substring(1);
        }
        byte[] data = IOUtils.readBytesAndClose(new FileInputStream(file), -1);
        ZipEntry entry = new ZipEntry(path);
        CRC32 crc = new CRC32();
        crc.update(data);
        entry.setSize(file.length());
        entry.setCrc(crc.getValue());
        out.putNextEntry(entry);
        out.write(data);
        out.closeEntry();
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:UploadBuild.java

示例7: setKeystore

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private static void setKeystore() throws IOException {
    Properties p = System.getProperties();
    if (p.getProperty(KEYSTORE_KEY) == null) {
        String fileName = KEYSTORE;
        byte[] data = getKeyStoreBytes(getKeyStore(
                KEYSTORE_PASSWORD), KEYSTORE_PASSWORD);
        boolean needWrite = true;
        if (FileUtils.exists(fileName) && FileUtils.size(fileName) == data.length) {
            // don't need to overwrite the file if it did not change
            InputStream fin = FileUtils.newInputStream(fileName);
            byte[] now = IOUtils.readBytesAndClose(fin, 0);
            if (now != null && Arrays.equals(data, now)) {
                needWrite = false;
            }
        }
        if (needWrite) {
            try {
                OutputStream out = FileUtils.newOutputStream(fileName, false);
                out.write(data);
                out.close();
            } catch (Exception e) {
                throw DbException.convertToIOException(e);
            }
        }
        String absolutePath = FileUtils.toRealPath(fileName);
        System.setProperty(KEYSTORE_KEY, absolutePath);
    }
    if (p.getProperty(KEYSTORE_PASSWORD_KEY) == null) {
        System.setProperty(KEYSTORE_PASSWORD_KEY, KEYSTORE_PASSWORD);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:32,代码来源:CipherFactory.java

示例8: createBlob

import org.h2.util.IOUtils; //导入方法依赖的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

示例9: getBytesNoCopy

import org.h2.util.IOUtils; //导入方法依赖的package包/类
@Override
public byte[] getBytesNoCopy() {
    if (type == CLOB) {
        // convert hex to string
        return super.getBytesNoCopy();
    }
    if (small != null) {
        return small;
    }
    try {
        return IOUtils.readBytesAndClose(getInputStream(), Integer.MAX_VALUE);
    } catch (IOException e) {
        throw DbException.convertIOException(e, toString());
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:16,代码来源:ValueLobDb.java

示例10: createTempBlob

import org.h2.util.IOUtils; //导入方法依赖的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

示例11: convert

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void convert() throws IOException {
    InputStream in = FileUtils.newInputStream(inFile);
    byte[] bytes = IOUtils.readBytesAndClose(in, -1);
    String s = new String(bytes, "UTF-8");
    String s2 = HtmlConverter.convertHtmlToString(s);
    String s3 = StringUtils.javaDecode(s2);
    byte[] result = s3.getBytes("UTF-8");
    OutputStream out = FileUtils.newOutputStream(outFile, false);
    out.write(result);
    out.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:12,代码来源:FileConverter.java

示例12: loadFragments

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void loadFragments() throws IOException {
    File dir = new File(SOURCE_DIR, "html");
    for (File f : dir.listFiles()) {
        if (f.getName().startsWith("fragments")) {
            FileInputStream in = new FileInputStream(f);
            byte[] bytes = IOUtils.readBytesAndClose(in, 0);
            String page = new String(bytes, "UTF-8");
            fragments.put(f.getName(), page);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:12,代码来源:WebSite.java

示例13: process

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void process(String dir, String fileName) throws Exception {
    String inFile = inDir + "/" + dir + "/" + fileName;
    String outFile = outDir + "/" + dir + "/" + fileName;
    new File(outFile).getParentFile().mkdirs();
    FileOutputStream out = new FileOutputStream(outFile);
    FileInputStream in = new FileInputStream(inFile);
    byte[] bytes = IOUtils.readBytesAndClose(in, 0);
    if (fileName.endsWith(".html")) {
        String page = new String(bytes);
        page = PageParser.parse(page, session);
        bytes = page.getBytes();
    }
    out.write(bytes);
    out.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:16,代码来源:GenerateDoc.java

示例14: load

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private static SortedProperties load(String fileName, boolean utf8)
        throws IOException {
    if (utf8) {
        String s = new String(IOUtils.readBytesAndClose(
                new FileInputStream(fileName), -1), "UTF-8");
        return SortedProperties.fromLines(s);
    }
    return SortedProperties.loadProperties(fileName);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:10,代码来源:PrepareTranslation.java

示例15: test

import org.h2.util.IOUtils; //导入方法依赖的package包/类
@Override
public void test() throws Exception {
    String s = "\u00ef\u00f6\u00fc";
    StringReader r = new StringReader(s);
    InputStream in = new ReaderInputStream(r);
    byte[] buff = IOUtils.readBytesAndClose(in, 0);
    InputStream in2 = new ByteArrayInputStream(buff);
    Reader r2 = IOUtils.getBufferedReader(in2);
    String s2 = IOUtils.readStringAndClose(r2, Integer.MAX_VALUE);
    assertEquals(s, s2);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:12,代码来源:TestReader.java


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