• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java IOUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: loadJSONFromResource

import org.h2.util.IOUtils; //导入依赖的package包/类
public static String loadJSONFromResource(String resname, ClassLoader loader) {
    System.out.println("Loading local resource: " + resname);

    try {
        InputStreamReader reader = new InputStreamReader(loader.getResourceAsStream(resname));
        StringWriter writer = new StringWriter();

        IOUtils.copyAndCloseInput(reader, writer, 100000000);

        writer.close();

        return writer.toString();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return "";
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:JSONReader.java


示例2: openWriter

import org.h2.util.IOUtils; //导入依赖的package包/类
private boolean openWriter() {
    if (printWriter == null) {
        try {
            FileUtils.createDirectories(FileUtils.getParent(fileName));
            if (FileUtils.exists(fileName) && !FileUtils.canWrite(fileName)) {
                // read only database: don't log error if the trace file
                // can't be opened
                return false;
            }
            fileWriter = IOUtils.getBufferedWriter(
                    FileUtils.newOutputStream(fileName, true));
            printWriter = new PrintWriter(fileWriter, true);
        } catch (Exception e) {
            logWritingError(e);
            return false;
        }
    }
    return true;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:TraceSystem.java


示例3: length

import org.h2.util.IOUtils; //导入依赖的package包/类
/**
 * Returns the length.
 *
 * @return the length
 */
@Override
public long length() throws SQLException {
    try {
        debugCodeCall("length");
        checkClosed();
        if (value.getType() == Value.CLOB) {
            long precision = value.getPrecision();
            if (precision > 0) {
                return precision;
            }
        }
        return IOUtils.copyAndCloseInput(value.getReader(), null, Long.MAX_VALUE);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:22,代码来源:JdbcClob.java


示例4: setAsciiStream

import org.h2.util.IOUtils; //导入依赖的package包/类
/**
 * Sets the value of a parameter as an ASCII stream.
 * This method does not close the stream.
 * The stream may be closed after executing the statement.
 *
 * @param parameterIndex the parameter index (1, 2, ...)
 * @param x the value
 * @param length the maximum number of bytes
 * @throws SQLException if this object is closed
 */
@Override
public void setAsciiStream(int parameterIndex, InputStream x, long length)
        throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("setAsciiStream("+parameterIndex+", x, "+length+"L);");
        }
        checkClosedForWrite();
        try {
            Value v = conn.createClob(IOUtils.getAsciiReader(x), length);
            setParameter(parameterIndex, v);
        } finally {
            afterWriting();
        }
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:29,代码来源:JdbcPreparedStatement.java


示例5: length

import org.h2.util.IOUtils; //导入依赖的package包/类
/**
 * Returns the length.
 *
 * @return the length
 */
@Override
public long length() throws SQLException {
    try {
        debugCodeCall("length");
        checkClosed();
        if (value.getType() == Value.BLOB) {
            long precision = value.getPrecision();
            if (precision > 0) {
                return precision;
            }
        }
        return IOUtils.copyAndCloseInput(value.getInputStream(), null);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:22,代码来源:JdbcBlob.java


示例6: 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


示例7: createFromReader

import org.h2.util.IOUtils; //导入依赖的package包/类
private void createFromReader(char[] buff, int len, Reader in,
        long remaining, DataHandler h) throws IOException {
    FileStoreOutputStream out = initLarge(h);
    boolean compress = h.getLobCompressionAlgorithm(Value.CLOB) != null;
    try {
        while (true) {
            precision += len;
            byte[] b = new String(buff, 0, len).getBytes(Constants.UTF8);
            out.write(b, 0, b.length);
            remaining -= len;
            if (remaining <= 0) {
                break;
            }
            len = getBufferSize(h, compress, remaining);
            len = IOUtils.readFully(in, buff, len);
            if (len == 0) {
                break;
            }
        }
    } finally {
        out.close();
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:ValueLob.java


示例8: createFromStream

import org.h2.util.IOUtils; //导入依赖的package包/类
private void createFromStream(byte[] buff, int len, InputStream in,
        long remaining, DataHandler h) throws IOException {
    FileStoreOutputStream out = initLarge(h);
    boolean compress = h.getLobCompressionAlgorithm(Value.BLOB) != null;
    try {
        while (true) {
            precision += len;
            out.write(buff, 0, len);
            remaining -= len;
            if (remaining <= 0) {
                break;
            }
            len = getBufferSize(h, compress, remaining);
            len = IOUtils.readFully(in, buff, len);
            if (len <= 0) {
                break;
            }
        }
    } finally {
        out.close();
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:ValueLob.java


示例9: 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


示例10: 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


示例11: 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


示例12: 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


示例13: installPgCatalog

import org.h2.util.IOUtils; //导入依赖的package包/类
private static void installPgCatalog(Statement stat) throws SQLException {
    Reader r = null;
    try {
        r = new InputStreamReader(new ByteArrayInputStream(Utils
                .getResource("/org/h2/server/pg/pg_catalog.sql")));
        ScriptReader reader = new ScriptReader(r);
        while (true) {
            String sql = reader.readStatement();
            if (sql == null) {
                break;
            }
            stat.execute(sql);
        }
        reader.close();
    } catch (IOException e) {
        throw DbException.convertIOException(e, "Can not read pg_catalog resource");
    } finally {
        IOUtils.closeSilently(r);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:PgServerThread.java


示例14: newOutputStream

import org.h2.util.IOUtils; //导入依赖的package包/类
@Override
public OutputStream newOutputStream(boolean append) throws IOException {
    try {
        File file = new File(name);
        File parent = file.getParentFile();
        if (parent != null) {
            FileUtils.createDirectories(parent.getAbsolutePath());
        }
        FileOutputStream out = new FileOutputStream(name, append);
        IOUtils.trace("openFileOutputStream", name, out);
        return out;
    } catch (IOException e) {
        freeMemoryAndFinalize();
        return new FileOutputStream(name);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:FilePathDisk.java


示例15: open

import org.h2.util.IOUtils; //导入依赖的package包/类
@Override
public FileChannel open(String mode) throws IOException {
    FileDisk f;
    try {
        f = new FileDisk(name, mode);
        IOUtils.trace("open", name, f);
    } catch (IOException e) {
        freeMemoryAndFinalize();
        try {
            f = new FileDisk(name, mode);
        } catch (IOException e2) {
            throw e;
        }
    }
    return f;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:FilePathDisk.java


示例16: run

import org.h2.util.IOUtils; //导入依赖的package包/类
@Override
public void run() {
    while (true) {
        try {
            int x = in.read();
            if (x < 0) {
                break;
            }
            openOutput();
            if (out != null) {
                out.write(x);
            }
        } catch (IOException e) {
            // ignore
        }
    }
    IOUtils.closeSilently(out);
    IOUtils.closeSilently(in);
    new File(processFile).delete();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:FtpServer.java


示例17: cat

import org.h2.util.IOUtils; //导入依赖的package包/类
private void cat(String fileName, long length) {
    if (!FileUtils.exists(fileName)) {
        print("No such file: " + fileName);
    }
    if (FileUtils.isDirectory(fileName)) {
        print("Is a directory: " + fileName);
    }
    InputStream inFile = null;
    try {
        inFile = FileUtils.newInputStream(fileName);
        IOUtils.copy(inFile, out, length);
    } catch (IOException e) {
        error(e);
    } finally {
        IOUtils.closeSilently(inFile);
    }
    println("");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:19,代码来源:FileShell.java


示例18: 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


示例19: processFile

import org.h2.util.IOUtils; //导入依赖的package包/类
private static void processFile(String fileName) throws Exception {
    int idx = fileName.lastIndexOf('.');
    if (idx < 0) {
        return;
    }
    String suffix = fileName.substring(idx + 1);
    if (!suffix.equals("html") && !suffix.equals("xml") && !suffix.equals("jsp")) {
        return;
    }
    // System.out.println("Checking file:" + fileName);
    FileReader reader = new FileReader(fileName);
    String s = IOUtils.readStringAndClose(reader, -1);
    Exception last = null;
    try {
        checkXML(s, !suffix.equals("xml"));
    } catch (Exception e) {
        last = e;
        System.out.println("ERROR in file " + fileName + " " + e.toString());
    }
    if (last != null) {
        last.printStackTrace();
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:XMLChecker.java


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AbstractJavaCompletionProposal类代码示例发布时间:2022-05-22
下一篇:
Java JavaParameter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap