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


Java IOUtils.copyAndClose方法代码示例

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


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

示例1: testHandle

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Test of handle method, of class Task.
 * @throws java.lang.Exception
 * @deprecated has to be implemented on a case by case basis
 */
@Test
public void testHandle() throws Exception {
    System.out.println("handle");
    EntityManager manager = new PersistenceProvider().get();
    manager.getTransaction().begin();
    IOUtils.copyAndClose(
        getClass().getResourceAsStream("/test.txt"),
        FileUtils.openOutputStream(new File(getAllowedFolder()+"/steamapps/common/Stellaris/test.txt"))
    );
    Original original = new Original("test.txt");
    manager.persist(original);
    manager.getTransaction().commit();
    List<ProcessTask> result = get(original.getAid()).handle(manager);
    Assert.assertEquals(
        "Follow-up number is wrong",
        1,
        result.size()
    );
    manager.getTransaction().begin();
    manager.refresh(original);
    Assert.assertTrue(
        "Content was not written",
        original.getContent().length() > 0
    );
    manager.getTransaction().commit();
}
 
开发者ID:Idrinths-Stellaris-Mods,项目名称:Mod-Tools,代码行数:32,代码来源:OriginalFileFillerTest.java

示例2: retrieve

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Read a file ([REST] RETR).
 *
 * @param fileName the file name
 * @param out the output stream
 * @param restartAt restart at the given position (0 if no restart is
 *            required).
 */
void retrieve(String fileName, OutputStream out, long restartAt)
        throws IOException {
    passive();
    if (restartAt > 0) {
        send("REST " + restartAt);
        readCode(350);
    }
    send("RETR " + fileName);
    IOUtils.copyAndClose(inData, out);
    readCode(150, 226);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:FtpClient.java

示例3: store

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Store a file (STOR).
 *
 * @param fileName the file name
 * @param in the input stream
 */
public void store(String fileName, InputStream in) throws IOException {
    passive();
    send("STOR " + fileName);
    readCode(150);
    IOUtils.copyAndClose(in, outData);
    readCode(226);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:14,代码来源:FtpClient.java

示例4: nameList

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Get the directory listing (NLST).
 *
 * @param dir the directory
 * @return the listing
 */
public String nameList(String dir) throws IOException {
    passive();
    send("NLST " + dir);
    readCode(150);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copyAndClose(inData, out);
    readCode(226);
    byte[] data = out.toByteArray();
    return new String(data);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:FtpClient.java

示例5: list

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Get the directory listing (LIST).
 *
 * @param dir the directory
 * @return the listing
 */
public String list(String dir) throws IOException {
    passive();
    send("LIST " + dir);
    readCode(150);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copyAndClose(inData, out);
    readCode(226);
    byte[] data = out.toByteArray();
    return new String(data);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:FtpClient.java

示例6: test

import org.h2.util.IOUtils; //导入方法依赖的package包/类
@Override
public void test() throws Exception {
    if (!getBaseDir().startsWith(TestBase.BASE_TEST_DIR)) {
        return;
    }
    deleteDb("optimizations");
    InputStream in = getClass().getClassLoader().getResourceAsStream(
            "org/h2/samples/optimizations.sql");
    new File(getBaseDir()).mkdirs();
    FileOutputStream out = new FileOutputStream(getBaseDir() +
            "/optimizations.sql");
    IOUtils.copyAndClose(in, out);
    String url = "jdbc:h2:" + getBaseDir() + "/optimizations";
    testApp("", org.h2.tools.RunScript.class, "-url", url, "-user", "sa",
            "-password", "sa", "-script", getBaseDir() +
                    "/optimizations.sql", "-checkResults");
    deleteDb("optimizations");
    testApp("Compacting...\nDone.", org.h2.samples.Compact.class);
    testApp("NAME: Bob Meier\n" +
            "EMAIL: [email protected]\n" +
            "PHONE: +41123456789\n\n" +
            "NAME: John Jones\n" +
            "EMAIL: [email protected]\n" +
            "PHONE: +41976543210\n",
            org.h2.samples.CsvSample.class);
    testApp("",
            org.h2.samples.CachedPreparedStatements.class);
    testApp("2 is prime\n" +
            "3 is prime\n" +
            "5 is prime\n" +
            "7 is prime\n" +
            "11 is prime\n" +
            "13 is prime\n" +
            "17 is prime\n" +
            "19 is prime\n" +
            "30\n" +
            "20\n" +
            "0/0\n" +
            "0/1\n" +
            "1/0\n" +
            "1/1\n" +
            "10",
            org.h2.samples.Function.class);
    // Not compatible with PostgreSQL JDBC driver (throws a
    // NullPointerException):
    // testApp(org.h2.samples.SecurePassword.class, null, "Joe");
    // TODO test ShowProgress (percent numbers are hardware specific)
    // TODO test ShutdownServer (server needs to be started in a separate
    // process)
    testApp("The sum is 20.00", org.h2.samples.TriggerSample.class);
    testApp("Hello: 1\nWorld: 2", org.h2.samples.TriggerPassData.class);
    testApp("table test:\n" +
            "1 Hallo\n\n" +
            "test_view:\n" +
            "1 Hallo",
            org.h2.samples.UpdatableView.class);
    testApp(
            "adding test data...\n" +
            "defrag to reduce random access...\n" +
            "create the zip file...\n" +
            "open the database from the zip file...",
            org.h2.samples.ReadOnlyDatabaseInZip.class);
    testApp(
            "a: 1/Hello!\n" +
            "b: 1/Hallo!\n" +
            "1/A/Hello!\n" +
            "1/B/Hallo!",
            org.h2.samples.RowAccessRights.class);

    // tools
    testApp("Allows changing the database file encryption password or algorithm*",
            org.h2.tools.ChangeFileEncryption.class, "-help");
    testApp("Allows changing the database file encryption password or algorithm*",
            org.h2.tools.ChangeFileEncryption.class);
    testApp("Deletes all files belonging to a database.*",
            org.h2.tools.DeleteDbFiles.class, "-help");
    FileUtils.delete(getBaseDir() + "/optimizations.sql");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:79,代码来源:TestSampleApps.java


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