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


Java FileUtils.newOutputStream方法代码示例

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


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

示例1: testCaseSensitiveColumnNames

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testCaseSensitiveColumnNames() throws Exception {
    OutputStream out = FileUtils.newOutputStream(
            getBaseDir() + "/test.tsv", false);
    out.write("lower,Mixed,UPPER\n 1 , 2, 3 \n".getBytes());
    out.close();
    Connection conn = getConnection("csv");
    Statement stat = conn.createStatement();
    ResultSet rs;
    rs = stat.executeQuery("select * from csvread('" +
            getBaseDir() + "/test.tsv')");
    rs.next();
    assertEquals("LOWER", rs.getMetaData().getColumnName(1));
    assertEquals("MIXED", rs.getMetaData().getColumnName(2));
    assertEquals("UPPER", rs.getMetaData().getColumnName(3));
    rs = stat.executeQuery("select * from csvread('" +
            getBaseDir() +
            "/test.tsv', null, 'caseSensitiveColumnNames=true')");
    rs.next();
    assertEquals("lower", rs.getMetaData().getColumnName(1));
    assertEquals("Mixed", rs.getMetaData().getColumnName(2));
    assertEquals("UPPER", rs.getMetaData().getColumnName(3));
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:TestCsv.java

示例2: run

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
@Override
public void run() {
    while (!stopNow) {
        try {
            SortedProperties sp = new SortedProperties();
            if (file.exists()) {
                InputStream in = FileUtils.newInputStream(file.getName());
                sp.load(in);
                translation.putAll(sp);
            } else {
                OutputStream out = FileUtils.newOutputStream(file.getName(), false);
                sp.putAll(translation);
                sp.store(out, "Translation");
            }
            Thread.sleep(1000);
        } catch (Exception e) {
            traceError(e);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:WebServer.java

示例3: store

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Store a properties file. The header and the date is not written.
 *
 * @param fileName the target file name
 */
public synchronized void store(String fileName) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    store(out, null);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    InputStreamReader reader = new InputStreamReader(in, "ISO8859-1");
    LineNumberReader r = new LineNumberReader(reader);
    Writer w;
    try {
        w = new OutputStreamWriter(FileUtils.newOutputStream(fileName, false));
    } catch (Exception e) {
        throw new IOException(e.toString(), e);
    }
    PrintWriter writer = new PrintWriter(new BufferedWriter(w));
    while (true) {
        String line = r.readLine();
        if (line == null) {
            break;
        }
        if (!line.startsWith("#")) {
            writer.print(line + "\n");
        }
    }
    writer.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:30,代码来源:SortedProperties.java

示例4: openOutput

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Open the output stream.
 */
void openOutput() {
    String file = getFileName();
    if (file == null) {
        return;
    }
    if (isEncrypted()) {
        initStore();
        out = new FileStoreOutputStream(store, this, compressionAlgorithm);
        // always use a big buffer, otherwise end-of-block is written a lot
        out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE_COMPRESS);
    } else {
        OutputStream o;
        try {
            o = FileUtils.newOutputStream(file, false);
        } catch (IOException e) {
            throw DbException.convertIOException(e, null);
        }
        out = new BufferedOutputStream(o, Constants.IO_BUFFER_SIZE);
        out = CompressTool.wrapOutputStream(out, compressionAlgorithm, SCRIPT_SQL);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:ScriptBase.java

示例5: testPreserveWhitespace

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testPreserveWhitespace() throws Exception {
    OutputStream out = FileUtils.newOutputStream(
            getBaseDir() + "/test.tsv", false);
    out.write("a,b\n 1 , 2 \n".getBytes());
    out.close();
    Connection conn = getConnection("csv");
    Statement stat = conn.createStatement();
    ResultSet rs;
    rs = stat.executeQuery("select * from csvread('" +
            getBaseDir() + "/test.tsv')");
    rs.next();
    assertEquals("1", rs.getString(1));
    assertEquals("2", rs.getString(2));
    rs = stat.executeQuery("select * from csvread('" +
            getBaseDir() + "/test.tsv', null, 'preserveWhitespace=true')");
    rs.next();
    assertEquals(" 1 ", rs.getString(1));
    assertEquals(" 2 ", rs.getString(2));
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:TestCsv.java

示例6: initWrite

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void initWrite() throws IOException {
    if (output == null) {
        try {
            OutputStream out = FileUtils.newOutputStream(fileName, false);
            out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE);
            output = new BufferedWriter(new OutputStreamWriter(out, characterSet));
        } catch (Exception e) {
            close();
            throw DbException.convertToIOException(e);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:13,代码来源:Csv.java

示例7: javacCompile

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Compile the given class. This method tries to use the class
 * "com.sun.tools.javac.Main" if available. If not, it tries to run "javac"
 * in a separate process.
 *
 * @param packageName the package name
 * @param className the class name
 * @param source the source code
 * @return the class file
 */
byte[] javacCompile(String packageName, String className, String source) {
    File dir = new File(COMPILE_DIR);
    if (packageName != null) {
        dir = new File(dir, packageName.replace('.', '/'));
        FileUtils.createDirectories(dir.getAbsolutePath());
    }
    File javaFile = new File(dir, className + ".java");
    File classFile = new File(dir, className + ".class");
    try {
        OutputStream f = FileUtils.newOutputStream(javaFile.getAbsolutePath(), false);
        Writer out = IOUtils.getBufferedWriter(f);
        classFile.delete();
        out.write(source);
        out.close();
        if (JAVAC_SUN != null) {
            javacSun(javaFile);
        } else {
            javacProcess(javaFile);
        }
        byte[] data = new byte[(int) classFile.length()];
        DataInputStream in = new DataInputStream(new FileInputStream(classFile));
        in.readFully(data);
        in.close();
        return data;
    } catch (Exception e) {
        throw DbException.convert(e);
    } finally {
        javaFile.delete();
        classFile.delete();
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:42,代码来源:SourceCompiler.java

示例8: log

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

示例9: openOutput

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void openOutput() {
    if (outFile != null) {
        try {
            this.out = FileUtils.newOutputStream(outFile, false);
        } catch (Exception e) {
            // ignore
        }
        outFile = null;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:11,代码来源:FtpServer.java

示例10: unzip

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

示例11: testLZFStreamClose

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testLZFStreamClose() throws IOException {
    String fileName = getBaseDir() + "/temp";
    FileUtils.createDirectories(FileUtils.getParent(fileName));
    OutputStream fo = FileUtils.newOutputStream(fileName, false);
    LZFOutputStream out = new LZFOutputStream(fo);
    out.write("Hello".getBytes());
    out.close();
    InputStream fi = FileUtils.newInputStream(fileName);
    LZFInputStream in = new LZFInputStream(fi);
    byte[] buff = new byte[100];
    assertEquals(5, in.read(buff));
    in.read();
    in.close();
    FileUtils.delete(getBaseDir() + "/temp");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:16,代码来源:TestStreams.java

示例12: testReadOnly

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testReadOnly(final String f) throws IOException {
    new AssertThrows(IOException.class) {
        @Override
        public void test() throws IOException {
            FileUtils.newOutputStream(f, false);
    }};
    new AssertThrows(DbException.class) {
        @Override
        public void test() {
            FileUtils.move(f, f);
    }};
    new AssertThrows(DbException.class) {
        @Override
        public void test() {
            FileUtils.move(f, f);
    }};
    new AssertThrows(IOException.class) {
        @Override
        public void test() throws IOException {
            FileUtils.createTempFile(f, ".tmp", false, false);
    }};
    final FileChannel channel = FileUtils.open(f, "r");
    new AssertThrows(IOException.class) {
        @Override
        public void test() throws IOException {
            channel.write(ByteBuffer.allocate(1));
    }};
    new AssertThrows(IOException.class) {
        @Override
        public void test() throws IOException {
            channel.truncate(0);
    }};
    assertTrue(null == channel.tryLock());
    channel.force(false);
    channel.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:37,代码来源:TestFileSystem.java

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

示例14: testFieldDelimiter

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void testFieldDelimiter() throws Exception {
    String fileName = getBaseDir() + "/test.csv";
    String fileName2 = getBaseDir() + "/test2.csv";
    FileUtils.delete(fileName);
    OutputStream out = FileUtils.newOutputStream(fileName, false);
    byte[] b = "'A'; 'B'\n\'It\\'s nice\'; '\nHello\\*\n'".getBytes();
    out.write(b, 0, b.length);
    out.close();
    Connection conn = getConnection("csv");
    Statement stat = conn.createStatement();
    ResultSet rs = stat.executeQuery("select * from csvread('" +
            fileName + "', null, null, ';', '''', '\\')");
    ResultSetMetaData meta = rs.getMetaData();
    assertEquals(2, meta.getColumnCount());
    assertEquals("A", meta.getColumnLabel(1));
    assertEquals("B", meta.getColumnLabel(2));
    assertTrue(rs.next());
    assertEquals("It's nice", rs.getString(1));
    assertEquals("\nHello*\n", rs.getString(2));
    assertFalse(rs.next());
    stat.execute("call csvwrite('" + fileName2 +
            "', 'select * from csvread(''" + fileName +
            "'', null, null, '';'', '''''''', ''\\'')', null, '+', '*', '#')");
    rs = stat.executeQuery("select * from csvread('" + fileName2 +
            "', null, null, '+', '*', '#')");
    meta = rs.getMetaData();
    assertEquals(2, meta.getColumnCount());
    assertEquals("A", meta.getColumnLabel(1));
    assertEquals("B", meta.getColumnLabel(2));
    assertTrue(rs.next());
    assertEquals("It's nice", rs.getString(1));
    assertEquals("\nHello*\n", rs.getString(2));
    assertFalse(rs.next());
    conn.close();
    FileUtils.delete(fileName);
    FileUtils.delete(fileName2);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:38,代码来源:TestCsv.java

示例15: testNull

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Test custom NULL string.
 */
private void testNull() throws Exception {
    deleteDb("csv");

    String fileName = getBaseDir() + "/testNull.csv";
    FileUtils.delete(fileName);

    OutputStream out = FileUtils.newOutputStream(fileName, false);
    String csvContent = "\"A\",\"B\",\"C\",\"D\"\n\\N,\"\",\"\\N\",";
    byte[] b = csvContent.getBytes("UTF-8");
    out.write(b, 0, b.length);
    out.close();
    Csv csv = new Csv();
    csv.setNullString("\\N");
    ResultSet rs = csv.read(fileName, null, "UTF8");
    ResultSetMetaData meta = rs.getMetaData();
    assertEquals(4, meta.getColumnCount());
    assertEquals("A", meta.getColumnLabel(1));
    assertEquals("B", meta.getColumnLabel(2));
    assertEquals("C", meta.getColumnLabel(3));
    assertEquals("D", meta.getColumnLabel(4));
    assertTrue(rs.next());
    assertEquals(null, rs.getString(1));
    assertEquals("", rs.getString(2));
    // null is never quoted
    assertEquals("\\N", rs.getString(3));
    // an empty string is always parsed as null
    assertEquals(null, rs.getString(4));
    assertFalse(rs.next());

    Connection conn = getConnection("csv");
    Statement stat = conn.createStatement();
    stat.execute("call csvwrite('" + fileName +
            "', 'select NULL as a, '''' as b, ''\\N'' as c, NULL as d', " +
            "'UTF8', ',', '\"', NULL, '\\N', '\n')");
    InputStreamReader reader = new InputStreamReader(
            FileUtils.newInputStream(fileName));
    // on read, an empty string is treated like null,
    // but on write a null is always written with the nullString
    String data = IOUtils.readStringAndClose(reader, -1);
    assertEquals(csvContent + "\\N", data.trim());
    conn.close();

    FileUtils.delete(fileName);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:48,代码来源:TestCsv.java


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