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


Java IOUtils.closeSilently方法代码示例

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


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

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

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

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

示例4: Profile

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private Profile() {
    LineNumberReader r = null;
    try {
        r = new LineNumberReader(new FileReader("profile.txt"));
        while (r.readLine() != null) {
            // nothing - just count lines
        }
        maxIndex = r.getLineNumber();
        count = new int[maxIndex];
        time = new int[maxIndex];
        lastTime = System.currentTimeMillis();
        Runtime.getRuntime().addShutdownHook(this);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        IOUtils.closeSilently(r);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:Profile.java

示例5: traceOperation

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Print a trace message to the trace file.
 *
 * @param s the message
 * @param e the exception or null
 */
protected void traceOperation(String s, Exception e) {
    FileWriter writer = null;
    try {
        File f = new File(getBaseDir() + "/" + TRACE_FILE_NAME);
        f.getParentFile().mkdirs();
        writer = new FileWriter(f, true);
        PrintWriter w = new PrintWriter(writer);
        s = dateFormat.format(new Date()) + ": " + s;
        w.println(s);
        if (e != null) {
            e.printStackTrace(w);
        }
    } catch (IOException e2) {
        e2.printStackTrace();
    } finally {
        IOUtils.closeSilently(writer);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:TestHalt.java

示例6: getVistaAccounts

import org.h2.util.IOUtils; //导入方法依赖的package包/类
protected synchronized List<VistaAccount> getVistaAccounts() {
    InputStream is = null;
    try {
        Resource vistaAccountConfig = getVistaAccountConfig();
        is = vistaAccountConfig.getInputStream();
        JsonNode json = jsonMapper.readTree(is);
        JsonNode items = json.path("data").path("items");
        List<VistaAccount> accounts = jsonMapper.convertValue(items, jsonMapper.getTypeFactory().constructCollectionType(List.class, VistaAccount.class));
        // quick and dirty way to set VistaAccount.id to its index in the list. Might be a fancier way to do it with Jackson...
        for (int i = 0; i < accounts.size(); i++) {
            accounts.get(i).setId(i);
            accounts.get(i).decrypt(hmpEncryption);
        }
        return accounts;
    } catch (Exception e) {
        throw new DataAccessResourceFailureException("unable to load vista-account config", e);
    } finally {
        IOUtils.closeSilently(is);
    }
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:21,代码来源:JsonVistaAccountDao.java

示例7: getPrimaryVistaSystemId

import org.h2.util.IOUtils; //导入方法依赖的package包/类
public String getPrimaryVistaSystemId() {
    InputStream is = null;
    try {
        Resource vistaAccountConfig = getVistaAccountConfig();
        is = vistaAccountConfig.getInputStream();
        JsonNode json = jsonMapper.readTree(is);
        JsonNode items = json.path("data").path("items");
        List<VistaAccount> accounts = jsonMapper.convertValue(items, jsonMapper.getTypeFactory().constructCollectionType(List.class, VistaAccount.class));
        // quick and dirty way to set VistaAccount.id to its index in the list. Might be a fancier way to do it with Jackson...
        if(accounts.size()>0) {
            return accounts.get(0).getVistaId();
        }
    } catch (Exception e) {
        throw new DataAccessResourceFailureException("unable to load vista-account config", e);
    } finally {
        IOUtils.closeSilently(is);
    }
    return "";
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:20,代码来源:JsonVistaAccountDao.java

示例8: getOriginalDbName

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private static String getOriginalDbName(String fileName, String db)
        throws IOException {
    InputStream in = null;
    try {
        in = FileUtils.newInputStream(fileName);
        ZipInputStream zipIn = new ZipInputStream(in);
        String originalDbName = null;
        boolean multiple = false;
        while (true) {
            ZipEntry entry = zipIn.getNextEntry();
            if (entry == null) {
                break;
            }
            String entryName = entry.getName();
            zipIn.closeEntry();
            String name = getDatabaseNameFromFileName(entryName);
            if (name != null) {
                if (db.equals(name)) {
                    originalDbName = name;
                    // we found the correct database
                    break;
                } else if (originalDbName == null) {
                    originalDbName = name;
                    // we found a database, but maybe another one
                } else {
                    // we have found multiple databases, but not the correct
                    // one
                    multiple = true;
                }
            }
        }
        zipIn.close();
        if (multiple && !db.equals(originalDbName)) {
            throw new IOException("Multiple databases found, but not " + db);
        }
        return originalDbName;
    } finally {
        IOUtils.closeSilently(in);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:41,代码来源:Restore.java

示例9: process

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void process(Connection conn, String fileName,
        boolean continueOnError, Charset charset) throws SQLException,
        IOException {
    InputStream in = FileUtils.newInputStream(fileName);
    String path = FileUtils.getParent(fileName);
    try {
        in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE);
        Reader reader = new InputStreamReader(in, charset);
        process(conn, continueOnError, path, reader, charset);
    } finally {
        IOUtils.closeSilently(in);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:14,代码来源:RunScript.java

示例10: close

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * INTERNAL
 */
@Override
public void close() {
    IOUtils.closeSilently(input);
    input = null;
    IOUtils.closeSilently(output);
    output = null;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:11,代码来源:Csv.java

示例11: closeIO

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Close input and output streams.
 */
void closeIO() {
    IOUtils.closeSilently(out);
    out = null;
    IOUtils.closeSilently(in);
    in = null;
    if (store != null) {
        store.closeSilently();
        store = null;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:14,代码来源:ScriptBase.java

示例12: log

import org.h2.util.IOUtils; //导入方法依赖的package包/类
@Override
public void log(int op, String fileName, byte[] data, long x) {
    if (op != Recorder.WRITE && op != Recorder.TRUNCATE) {
        return;
    }
    if (!fileName.endsWith(Constants.SUFFIX_PAGE_FILE) &&
            !fileName.endsWith(Constants.SUFFIX_MV_FILE)) {
        return;
    }
    writeCount++;
    if ((writeCount % testEvery) != 0) {
        return;
    }
    if (FileUtils.size(fileName) > maxFileSize) {
        // System.out.println(fileName + " " + IOUtils.length(fileName));
        return;
    }
    if (testing) {
        // avoid deadlocks
        return;
    }
    testing = true;
    PrintWriter out = null;
    try {
        out = new PrintWriter(
                new OutputStreamWriter(
                FileUtils.newOutputStream(fileName + ".log", true)));
        testDatabase(fileName, out);
    } catch (IOException e) {
        throw DbException.convertIOException(e, null);
    } finally {
        IOUtils.closeSilently(out);
        testing = false;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:36,代码来源:RecoverTester.java

示例13: unzip

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void unzip(String zipFileName, String targetDir) {
    InputStream inFile = null;
    try {
        inFile = FileUtils.newInputStream(zipFileName);
        ZipInputStream zipIn = new ZipInputStream(inFile);
        while (true) {
            ZipEntry entry = zipIn.getNextEntry();
            if (entry == null) {
                break;
            }
            String fileName = entry.getName();
            // restoring windows backups on linux and vice versa
            fileName = fileName.replace('\\',
                    SysProperties.FILE_SEPARATOR.charAt(0));
            fileName = fileName.replace('/',
                    SysProperties.FILE_SEPARATOR.charAt(0));
            if (fileName.startsWith(SysProperties.FILE_SEPARATOR)) {
                fileName = fileName.substring(1);
            }
            OutputStream o = null;
            try {
                o = FileUtils.newOutputStream(targetDir
                        + SysProperties.FILE_SEPARATOR + fileName, false);
                IOUtils.copy(zipIn, o);
                o.close();
            } finally {
                IOUtils.closeSilently(o);
            }
            zipIn.closeEntry();
        }
        zipIn.closeEntry();
        zipIn.close();
    } catch (IOException e) {
        error(e);
    } finally {
        IOUtils.closeSilently(inFile);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:39,代码来源:FileShell.java

示例14: listUnvisited

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void listUnvisited() throws IOException {
    printLine('=');
    print("NOT COVERED");
    printLine('-');
    LineNumberReader r = null;
    BufferedWriter writer = null;
    try {
        r = new LineNumberReader(new FileReader("profile.txt"));
        writer = new BufferedWriter(new FileWriter("notCovered.txt"));
        int unvisited = 0;
        int unvisitedThrow = 0;
        for (int i = 0; i < maxIndex; i++) {
            String line = r.readLine();
            if (count[i] == 0) {
                if (!line.endsWith("throw")) {
                    writer.write(line + "\r\n");
                    if (LIST_UNVISITED) {
                        print(line + "\r\n");
                    }
                    unvisited++;
                } else {
                    unvisitedThrow++;
                }
            }
        }
        int percent = 100 * unvisited / maxIndex;
        print("Not covered: " + percent + " % " + " (" +
                unvisited + " of " + maxIndex + "; throw=" +
                unvisitedThrow + ")");
    } finally {
        IOUtils.closeSilently(writer);
        IOUtils.closeSilently(r);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:35,代码来源:Profile.java

示例15: run

import org.h2.util.IOUtils; //导入方法依赖的package包/类
@Override
public void run() {
    StringBuilder buff = new StringBuilder();
    while (true) {
        try {
            int x = in.read();
            if (x < 0) {
                break;
            }
            if (x < ' ') {
                if (buff.length() > 0) {
                    String s = buff.toString();
                    buff.setLength(0);
                    synchronized (list) {
                        list.add(s);
                        list.notifyAll();
                    }
                }
            } else {
                buff.append((char) x);
            }
        } catch (IOException e) {
            break;
        }
    }
    IOUtils.closeSilently(in);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:28,代码来源:OutputCatcher.java


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