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


Java FileHelper.copy方法代码示例

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


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

示例1: overwriteFileWithDefaults

import org.apache.metamodel.util.FileHelper; //导入方法依赖的package包/类
private static FileObject overwriteFileWithDefaults(final FileObject targetDirectory, final String targetFilename)
        throws FileSystemException {
    final FileObject file = targetDirectory.resolveFile(targetFilename);
    final FileObject parentFile = file.getParent();
    if (!parentFile.exists()) {
        parentFile.createFolder();
    }

    final ResourceManager resourceManager = ResourceManager.get();
    final URL url = resourceManager.getUrl("datacleaner-home/" + targetFilename);
    if (url == null) {
        return null;
    }

    InputStream in = null;
    OutputStream out = null;
    try {
        in = url.openStream();
        out = file.getContent().getOutputStream();

        FileHelper.copy(in, out);
    } catch (final IOException e) {
        throw new IllegalArgumentException(e);
    } finally {
        FileHelper.safeClose(in, out);
    }

    return file;
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:30,代码来源:DataCleanerHomeUpgrader.java

示例2: copyIfNonExisting

import org.apache.metamodel.util.FileHelper; //导入方法依赖的package包/类
private static FileObject copyIfNonExisting(final FileObject candidate, final FileSystemManager manager,
        final String filename) throws FileSystemException {
    final FileObject file = candidate.resolveFile(filename);
    if (file.exists()) {
        logger.info("File already exists in DATACLEANER_HOME: " + filename);
        return file;
    }
    final FileObject parentFile = file.getParent();
    if (!parentFile.exists()) {
        parentFile.createFolder();
    }

    final ResourceManager resourceManager = ResourceManager.get();
    final URL url = resourceManager.getUrl("datacleaner-home/" + filename);
    if (url == null) {
        return null;
    }

    InputStream in = null;
    OutputStream out = null;
    try {
        in = url.openStream();
        out = file.getContent().getOutputStream();

        FileHelper.copy(in, out);
    } catch (final IOException e) {
        throw new IllegalArgumentException(e);
    } finally {
        FileHelper.safeClose(in, out);
    }

    return file;
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:34,代码来源:DataCleanerHome.java

示例3: testErrorHandlingToAppendingFile

import org.apache.metamodel.util.FileHelper; //导入方法依赖的package包/类
public void testErrorHandlingToAppendingFile() throws Exception {
    final File file = new File("target/valid-error-handling-file.csv");
    FileHelper.copy(new File("src/test/resources/valid-error-handling-file.csv"), file);

    final InsertIntoTableAnalyzer insertIntoTable = new InsertIntoTableAnalyzer();
    insertIntoTable.datastore = jdbcDatastore;
    insertIntoTable.tableName = "test_table";
    insertIntoTable.columnNames = new String[] { "foo", "bar" };
    insertIntoTable.errorHandlingOption = ErrorHandlingOption.SAVE_TO_FILE;
    insertIntoTable.errorLogFile = file;

    final InputColumn<Object> col1 = new MockInputColumn<>("in1", Object.class);
    final InputColumn<Object> col2 = new MockInputColumn<>("in2", Object.class);

    insertIntoTable.values = new InputColumn[] { col1, col2 };

    insertIntoTable.validate();
    insertIntoTable.init();

    insertIntoTable.run(new MockInputRow().put(col1, "blabla").put(col2, "hello int"), 2);

    final WriteDataResult result = insertIntoTable.getResult();
    assertEquals(0, result.getWrittenRowCount());
    assertEquals(2, result.getErrorRowCount());

    assertEquals("foo,bar,extra1,insert_into_table_error_message,extra2[newline]" + "f,b,e1,m,e2[newline]"
                    + "\"blabla\",\"hello int\",\"\",\"Could not convert hello int to number\",\"\"[newline]"
                    + "\"blabla\",\"hello int\",\"\",\"Could not convert hello int to number\",\"\"",
            FileHelper.readFileAsString(file).replaceAll("\n", "\\[newline\\]"));
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:31,代码来源:InsertIntoTableAnalyzerTest.java

示例4: shouldCorrectlyAppendErrorHandlingInfo

import org.apache.metamodel.util.FileHelper; //导入方法依赖的package包/类
@Test
public void shouldCorrectlyAppendErrorHandlingInfo() throws Exception {
    final File file = new File("target/valid-error-handling-file-for-update.csv.csv");
    FileHelper.copy(new File("src/test/resources/valid-error-handling-file-for-update.csv"), file);

    final DeleteFromTableAnalyzer deleteFromTable = new DeleteFromTableAnalyzer();
    deleteFromTable.datastore = updateableDatastore;
    deleteFromTable.tableName = TEST_TABLE_NAME;
    deleteFromTable.errorHandlingOption = ErrorHandlingOption.SAVE_TO_FILE;
    deleteFromTable.errorLogFile = file;
    deleteFromTable.conditionColumnNames = new String[] { INTEGER_COLUMN_NAME };

    final InputColumn<Object> inputColumn = new MockInputColumn<>(INTEGER_COLUMN_NAME, Object.class);
    deleteFromTable.conditionValues = new InputColumn[] { inputColumn };

    deleteFromTable.validate();
    deleteFromTable.init();

    deleteFromTable.run(new MockInputRow().put(inputColumn, "blabla"), 1);

    final WriteDataResult result = deleteFromTable.getResult();
    assertThat(result.getUpdatesCount(), is(0));
    assertThat(result.getErrorRowCount(), is(1));
    assertThat(FileHelper.readFileAsString(file).replaceAll("\n", "\\[newline\\]"),
            is(equalTo("foo,bar,extra1,update_table_error_message,extra2[newline]" + //
                    "f,b,e1,m,e2[newline]" + //
                    "\"\",\"\",\"\",\"Could not convert blabla to number\",\"\"")));//
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:29,代码来源:DeleteFromTableAnalyzerTest.java

示例5: testErrorHandlingToAppendingFile

import org.apache.metamodel.util.FileHelper; //导入方法依赖的package包/类
public void testErrorHandlingToAppendingFile() throws Exception {
    final File file = new File("target/valid-error-handling-file.csv");
    FileHelper.copy(new File("src/test/resources/valid-error-handling-file.csv"), file);

    final InsertIntoTableAnalyzer insertIntoTable = new InsertIntoTableAnalyzer();
    insertIntoTable.datastore = jdbcDatastore;
    insertIntoTable.tableName = "test_table";
    insertIntoTable.columnNames = new String[] { "foo", "bar" };
    insertIntoTable.errorHandlingOption = ErrorHandlingOption.SAVE_TO_FILE;
    insertIntoTable.errorLogFile = file;

    InputColumn<Object> col1 = new MockInputColumn<Object>("in1", Object.class);
    InputColumn<Object> col2 = new MockInputColumn<Object>("in2", Object.class);

    insertIntoTable.values = new InputColumn[] { col1, col2 };

    insertIntoTable.validate();
    insertIntoTable.init();

    insertIntoTable.run(new MockInputRow().put(col1, "blabla").put(col2, "hello int"), 2);

    WriteDataResult result = insertIntoTable.getResult();
    assertEquals(0, result.getWrittenRowCount());
    assertEquals(2, result.getErrorRowCount());

    assertEquals("foo,bar,extra1,insert_into_table_error_message,extra2[newline]" + "f,b,e1,m,e2[newline]"
            + "\"blabla\",\"hello int\",\"\",\"Could not convert hello int to number\",\"\"[newline]"
            + "\"blabla\",\"hello int\",\"\",\"Could not convert hello int to number\",\"\"", FileHelper
            .readFileAsString(file).replaceAll("\n", "\\[newline\\]"));
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:31,代码来源:InsertIntoTableAnalyzerTest.java

示例6: testUpdateCSV

import org.apache.metamodel.util.FileHelper; //导入方法依赖的package包/类
public void testUpdateCSV() throws Exception {
    final File file = new File("target/example_updated.csv");
    FileHelper.copy(new File("src/test/resources/example_updated.csv"), file);

    final CsvDatastore datastore = new CsvDatastore("example", file.getPath(), null, ',', "UTF8");
    final UpdateableDatastoreConnection connection = datastore.openConnection();
    final DataContext dataContext = connection.getDataContext();
    final Schema schema = dataContext.getDefaultSchema();
    final Table table = schema.getTable(0);

    final UpdateTableAnalyzer updateTableAnalyzer = new UpdateTableAnalyzer();
    updateTableAnalyzer.datastore = datastore;
    updateTableAnalyzer.schemaName = schema.getName();
    updateTableAnalyzer.tableName = table.getName();
    updateTableAnalyzer.columnNames = new String[] { "name" };
    updateTableAnalyzer.conditionColumnNames = new String[] { "id" };
    updateTableAnalyzer.errorHandlingOption = ErrorHandlingOption.SAVE_TO_FILE;
    updateTableAnalyzer._componentContext = EasyMock.createMock(ComponentContext.class);

    final InputColumn<Object> inputId = new MockInputColumn<>("id", Object.class);
    final InputColumn<Object> inputNewName = new MockInputColumn<>("new_name", Object.class);
    updateTableAnalyzer.values = new InputColumn[] { inputNewName };
    updateTableAnalyzer.conditionValues = new InputColumn[] { inputId };

    updateTableAnalyzer.validate();
    updateTableAnalyzer.init();

    updateTableAnalyzer.run(new MockInputRow().put(inputId, 1).put(inputNewName, "foo"), 1);
    updateTableAnalyzer.run(new MockInputRow().put(inputId, "2").put(inputNewName, "bar"), 1);
    updateTableAnalyzer.run(new MockInputRow().put(inputId, 3).put(inputNewName, "baz"), 1);

    final WriteDataResult result = updateTableAnalyzer.getResult();
    assertEquals(0, result.getErrorRowCount());
    assertEquals(0, result.getWrittenRowCount());
    assertEquals(3, result.getUpdatesCount());

    final DataSet dataSet = dataContext.query().from(table).select("id", "name").execute();
    assertTrue(dataSet.next());
    assertEquals("Row[values=[4, hans]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[5, manuel]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[6, ankit]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[1, foo]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[2, bar]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[3, baz]]", dataSet.getRow().toString());
    assertFalse(dataSet.next());

    connection.close();
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:54,代码来源:UpdateTableAnalyzerTest.java

示例7: testUpdateCSV

import org.apache.metamodel.util.FileHelper; //导入方法依赖的package包/类
public void testUpdateCSV() throws Exception {
    final File file = new File("target/example_updated.csv");
    FileHelper.copy(new File("src/test/resources/example_updated.csv"), file);

    final CsvDatastore datastore = new CsvDatastore("example", file.getPath(), null, ',', "UTF8");
    final UpdateableDatastoreConnection connection = datastore.openConnection();
    final DataContext dataContext = connection.getDataContext();
    final Schema schema = dataContext.getDefaultSchema();
    final Table table = schema.getTable(0);

    final UpdateTableAnalyzer updateTableAnalyzer = new UpdateTableAnalyzer();
    updateTableAnalyzer.datastore = datastore;
    updateTableAnalyzer.schemaName = schema.getName();
    updateTableAnalyzer.tableName = table.getName();
    updateTableAnalyzer.columnNames = new String[] { "name" };
    updateTableAnalyzer.conditionColumnNames = new String[] { "id" };
    updateTableAnalyzer.errorHandlingOption = ErrorHandlingOption.SAVE_TO_FILE;
    updateTableAnalyzer._componentContext = EasyMock.createMock(ComponentContext.class);

    InputColumn<Object> inputId = new MockInputColumn<Object>("id", Object.class);
    InputColumn<Object> inputNewName = new MockInputColumn<Object>("new_name", Object.class);
    updateTableAnalyzer.values = new InputColumn[] { inputNewName };
    updateTableAnalyzer.conditionValues = new InputColumn[] { inputId };

    updateTableAnalyzer.validate();
    updateTableAnalyzer.init();

    updateTableAnalyzer.run(new MockInputRow().put(inputId, 1).put(inputNewName, "foo"), 1);
    updateTableAnalyzer.run(new MockInputRow().put(inputId, "2").put(inputNewName, "bar"), 1);
    updateTableAnalyzer.run(new MockInputRow().put(inputId, 3).put(inputNewName, "baz"), 1);

    WriteDataResult result = updateTableAnalyzer.getResult();
    assertEquals(0, result.getErrorRowCount());
    assertEquals(0, result.getWrittenRowCount());
    assertEquals(3, result.getUpdatesCount());

    DataSet dataSet = dataContext.query().from(table).select("id", "name").execute();
    assertTrue(dataSet.next());
    assertEquals("Row[values=[4, hans]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[5, manuel]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[6, ankit]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[1, foo]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[2, bar]]", dataSet.getRow().toString());
    assertTrue(dataSet.next());
    assertEquals("Row[values=[3, baz]]", dataSet.getRow().toString());
    assertFalse(dataSet.next());

    connection.close();
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:54,代码来源:UpdateTableAnalyzerTest.java


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