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


Java FileUtils.newInputStream方法代码示例

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


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

示例1: testEmptyFieldDelimiter

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testEmptyFieldDelimiter() throws Exception {
    String fileName = getBaseDir() + "/test.csv";
    FileUtils.delete(fileName);
    Connection conn = getConnection("csv");
    Statement stat = conn.createStatement();
    stat.execute("call csvwrite('" + fileName
            + "', 'select 1 id, ''Hello'' name', null, '|', '', null, null, chr(10))");
    InputStreamReader reader = new InputStreamReader(
            FileUtils.newInputStream(fileName));
    String text = IOUtils.readStringAndClose(reader, -1).trim();
    text = StringUtils.replaceAll(text, "\n", " ");
    assertEquals("ID|NAME 1|Hello", text);
    ResultSet rs = stat.executeQuery("select * from csvread('" +
            fileName + "', null, null, '|', '')");
    ResultSetMetaData meta = rs.getMetaData();
    assertEquals(2, meta.getColumnCount());
    assertEquals("ID", meta.getColumnLabel(1));
    assertEquals("NAME", meta.getColumnLabel(2));
    assertTrue(rs.next());
    assertEquals("1", rs.getString(1));
    assertEquals("Hello", rs.getString(2));
    assertFalse(rs.next());
    conn.close();
    FileUtils.delete(fileName);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:26,代码来源:TestCsv.java

示例2: loadProperties

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Load a properties object from a file.
 *
 * @param fileName the name of the properties file
 * @return the properties object
 */
public static synchronized SortedProperties loadProperties(String fileName)
        throws IOException {
    SortedProperties prop = new SortedProperties();
    if (FileUtils.exists(fileName)) {
        InputStream in = null;
        try {
            in = FileUtils.newInputStream(fileName);
            prop.load(in);
        } finally {
            if (in != null) {
                in.close();
            }
        }
    }
    return prop;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:SortedProperties.java

示例3: openInput

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Open the input stream.
 */
void openInput() {
    String file = getFileName();
    if (file == null) {
        return;
    }
    if (isEncrypted()) {
        initStore();
        in = new FileStoreInputStream(store, this, compressionAlgorithm != null, false);
    } else {
        InputStream inStream;
        try {
            inStream = FileUtils.newInputStream(file);
        } catch (IOException e) {
            throw DbException.convertIOException(e, file);
        }
        in = new BufferedInputStream(inStream, Constants.IO_BUFFER_SIZE);
        in = CompressTool.wrapInputStream(in, compressionAlgorithm, SCRIPT_SQL);
        if (in == null) {
            throw DbException.get(ErrorCode.FILE_NOT_FOUND_1, SCRIPT_SQL + " in " + file);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:26,代码来源:ScriptBase.java

示例4: cat

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

示例5: testLogLimitFalsePositive

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testLogLimitFalsePositive() throws Exception {
    deleteDb("pageStoreLogLimitFalsePositive");
    String url = "pageStoreLogLimitFalsePositive;TRACE_LEVEL_FILE=2";
    Connection conn = getConnection(url);
    Statement stat = conn.createStatement();
    stat.execute("set max_log_size 1");
    stat.execute("create table test(x varchar)");
    for (int i = 0; i < 1000; ++i) {
        stat.execute("insert into test values (space(2000))");
    }
    stat.execute("checkpoint");
    InputStream in = FileUtils.newInputStream(getBaseDir() +
            "/pageStoreLogLimitFalsePositive.trace.db");
    String s = IOUtils.readStringAndClose(new InputStreamReader(in), -1);
    assertFalse(s.indexOf("Transaction log could not be truncated") > 0);
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:18,代码来源:TestPageStore.java

示例6: runFile

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void runFile(String fileName) throws IOException {
    LineNumberReader reader = new LineNumberReader(new BufferedReader(
            new InputStreamReader(FileUtils.newInputStream(fileName))));
    while (true) {
        String line = reader.readLine();
        if (line == null) {
            break;
        }
        runLine(line.trim());
    }
    reader.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:13,代码来源:Player.java

示例7: openScriptReader

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Open a script reader.
 *
 * @param fileName the file name (the file will be overwritten)
 * @param compressionAlgorithm the compression algorithm (uppercase)
 * @param cipher the encryption algorithm or null
 * @param password the encryption password
 * @param charset the character set (for example UTF-8)
 * @return the script reader
 */
public static LineNumberReader openScriptReader(String fileName,
        String compressionAlgorithm,
        String cipher, String password,
        String charset) throws IOException {
    try {
        InputStream in;
        if (cipher != null) {
            byte[] key = SHA256.getKeyPasswordHash("script", password.toCharArray());
            FileStore store = FileStore.open(null, fileName, "rw", cipher, key);
            store.init();
            in = new FileStoreInputStream(store, null,
                    compressionAlgorithm != null, false);
            in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE_COMPRESS);
        } else {
            in = FileUtils.newInputStream(fileName);
            in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE);
            in = CompressTool.wrapInputStream(in, compressionAlgorithm, "script.sql");
            if (in == null) {
                throw new IOException("Entry not found: script.sql in " + fileName);
            }
        }
        return new LineNumberReader(new InputStreamReader(in, charset));
    } catch (Exception e) {
        throw new IOException(e.getMessage(), e);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:37,代码来源:CreateScriptFile.java

示例8: getOriginalDbName

import org.h2.store.fs.FileUtils; //导入方法依赖的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.store.fs.FileUtils; //导入方法依赖的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: send

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

示例11: testFileRead

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testFileRead() throws Exception {
    Connection conn = getConnection("functions");
    Statement stat = conn.createStatement();
    String fileName = getBaseDir() + "/test.txt";
    Properties prop = System.getProperties();
    OutputStream out = FileUtils.newOutputStream(fileName, false);
    prop.store(out, "");
    out.close();
    ResultSet rs = stat.executeQuery("SELECT LENGTH(FILE_READ('" +
            fileName + "')) LEN");
    rs.next();
    assertEquals(FileUtils.size(fileName), rs.getInt(1));
    rs = stat.executeQuery("SELECT FILE_READ('" +
            fileName + "') PROP");
    rs.next();
    Properties p2 = new Properties();
    p2.load(rs.getBinaryStream(1));
    assertEquals(prop.size(), p2.size());
    rs = stat.executeQuery("SELECT FILE_READ('" +
            fileName + "', NULL) PROP");
    rs.next();
    String ps = rs.getString(1);
    InputStreamReader r = new InputStreamReader(FileUtils.newInputStream(fileName));
    String ps2 = IOUtils.readStringAndClose(r, -1);
    assertEquals(ps, ps2);
    conn.close();
    FileUtils.delete(fileName);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:29,代码来源:TestFunctions.java

示例12: convert

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

示例13: testLogLimit

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testLogLimit() throws Exception {
    if (config.mvStore) {
        return;
    }
    deleteDb("pageStoreLogLimit");
    Connection conn, conn2;
    Statement stat, stat2;
    String url = "pageStoreLogLimit;TRACE_LEVEL_FILE=2";
    conn = getConnection(url);
    stat = conn.createStatement();
    stat.execute("create table test(id int primary key)");
    conn.setAutoCommit(false);
    stat.execute("insert into test values(1)");

    conn2 = getConnection(url);
    stat2 = conn2.createStatement();
    stat2.execute("create table t2(id identity, name varchar)");
    stat2.execute("set max_log_size 1");
    for (int i = 0; i < 10; i++) {
        stat2.execute("insert into t2(name) " +
                "select space(100) from system_range(1, 1000)");
    }
    InputStream in = FileUtils.newInputStream(getBaseDir() +
            "/pageStoreLogLimit.trace.db");
    String s = IOUtils.readStringAndClose(new InputStreamReader(in), -1);
    assertTrue(s.indexOf("Transaction log could not be truncated") > 0);
    conn.commit();
    ResultSet rs = stat2.executeQuery("select * from test");
    assertTrue(rs.next());
    conn2.close();
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:33,代码来源:TestPageStore.java

示例14: execute

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Restores database files.
 *
 * @param zipFileName the name of the backup file
 * @param directory the directory name
 * @param db the database name (null for all databases)
 * @throws DbException if there is an IOException
 */
public static void execute(String zipFileName, String directory, String db) {
    InputStream in = null;
    try {
        if (!FileUtils.exists(zipFileName)) {
            throw new IOException("File not found: " + zipFileName);
        }
        String originalDbName = null;
        int originalDbLen = 0;
        if (db != null) {
            originalDbName = getOriginalDbName(zipFileName, db);
            if (originalDbName == null) {
                throw new IOException("No database named " + db + " found");
            }
            if (originalDbName.startsWith(SysProperties.FILE_SEPARATOR)) {
                originalDbName = originalDbName.substring(1);
            }
            originalDbLen = originalDbName.length();
        }
        in = FileUtils.newInputStream(zipFileName);
        ZipInputStream zipIn = new ZipInputStream(in);
        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);
            }
            boolean copy = false;
            if (db == null) {
                copy = true;
            } else if (fileName.startsWith(originalDbName + ".")) {
                fileName = db + fileName.substring(originalDbLen);
                copy = true;
            }
            if (copy) {
                OutputStream o = null;
                try {
                    o = FileUtils.newOutputStream(
                            directory + SysProperties.FILE_SEPARATOR + fileName, false);
                    IOUtils.copy(zipIn, o);
                    o.close();
                } finally {
                    IOUtils.closeSilently(o);
                }
            }
            zipIn.closeEntry();
        }
        zipIn.closeEntry();
        zipIn.close();
    } catch (IOException e) {
        throw DbException.convertIOException(e, zipFileName);
    } finally {
        IOUtils.closeSilently(in);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:69,代码来源:Restore.java

示例15: readBlob

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * INTERNAL
 */
public static InputStream readBlob(String fileName) throws IOException {
    return new BufferedInputStream(FileUtils.newInputStream(fileName));
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:7,代码来源:Recover.java


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