本文整理汇总了Java中org.databene.commons.IOUtil.close方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtil.close方法的具体用法?Java IOUtil.close怎么用?Java IOUtil.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.databene.commons.IOUtil
的用法示例。
在下文中一共展示了IOUtil.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: next
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
@Override
public DataContainer<ResultSet> next(DataContainer<ResultSet> container) {
LOGGER.debug("next() called on {}", this);
if (resultSet == null)
return null;
try {
if (resultSet.next()) {
return container.setData(resultSet);
} else {
IOUtil.close(this);
return null;
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例2: exportColumns
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
private void exportColumns(Database database) throws IOException {
File file = new File(rootDirectory, "colums.csv");
PrintWriter out = null;
try {
out = createPrintWriter(file);
out.print(CSVUtil.formatHeaderWithLineFeed(',', "catalog", "schema", "table", "column_name",
"type", "jdbc_type", "nullable", "defaultValue"));
for (DBTable table : database.getTables()) {
for (DBColumn column : table.getColumns()) {
CSVUtil.writeRow(out, ',',
table.getCatalog().getName(),
table.getSchema().getName(),
table.getName(),
column.getName(),
SQLUtil.renderColumnTypeWithSize(column),
String.valueOf(column.getType().getJdbcType()),
String.valueOf(column.isNullable()),
column.getDefaultValue());
}
}
} finally {
IOUtil.close(out);
}
}
示例3: exportPrimaryKeys
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
private void exportPrimaryKeys(Database database) throws IOException {
File file = new File(rootDirectory, "primary_keys.csv");
PrintWriter out = null;
try {
out = createPrintWriter(file);
out.print(CSVUtil.formatHeaderWithLineFeed(',', "catalog", "schema", "table", "pk_name", "column_name"));
for (DBTable table : database.getTables()) {
DBPrimaryKeyConstraint pk = table.getPrimaryKeyConstraint();
if (pk == null)
continue;
for (String columnName : pk.getColumnNames()) {
CSVUtil.writeRow(out, ',',
table.getCatalog().getName(),
table.getSchema().getName(),
table.getName(),
pk.getName(),
columnName);
}
}
} finally {
IOUtil.close(out);
}
}
示例4: exportUniqueKeys
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
private void exportUniqueKeys(Database database) throws IOException {
File file = new File(rootDirectory, "unique_keys.csv");
PrintWriter out = null;
try {
out = createPrintWriter(file);
out.print(CSVUtil.formatHeaderWithLineFeed(',', "catalog", "schema", "table", "uk_name", "column_name"));
for (DBTable table : database.getTables()) {
for (DBUniqueConstraint uk : table.getUniqueConstraints(false)) {
for (String columnName : uk.getColumnNames()) {
CSVUtil.writeRow(out, ',',
table.getCatalog().getName(),
table.getSchema().getName(),
table.getName(),
uk.getName(),
columnName);
}
}
}
} finally {
IOUtil.close(out);
}
}
示例5: exportChecks
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
private void exportChecks(Database database) throws IOException {
File file = new File(rootDirectory, "checks.csv");
PrintWriter out = null;
try {
out = createPrintWriter(file);
out.print(CSVUtil.formatHeaderWithLineFeed(',', "catalog", "schema", "table", "check"));
for (DBTable table : database.getTables()) {
for (DBCheckConstraint check : table.getCheckConstraints()) {
CSVUtil.writeRow(out, ',',
table.getCatalog().getName(),
table.getSchema().getName(),
table.getName(),
check.getName(),
SQLUtil.normalize(check.getConditionText(), true));
}
}
} finally {
IOUtil.close(out);
}
}
示例6: exportIndexes
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
private void exportIndexes(Database database) throws IOException {
File file = new File(rootDirectory, "indexes.csv");
PrintWriter out = null;
try {
out = createPrintWriter(file);
out.print(CSVUtil.formatHeaderWithLineFeed(',',
"catalog", "schema", "table", "index_name", "index_unique", "column_name"));
for (DBTable table : database.getTables()) {
for (DBIndex index : table.getIndexes()) {
for (String columnName : index.getColumnNames()) {
CSVUtil.writeRow(out, ',',
table.getCatalog().getName(),
table.getSchema().getName(),
table.getName(),
index.getName(),
String.valueOf(index.isUnique()),
columnName);
}
}
}
} finally {
IOUtil.close(out);
}
}
示例7: testOnline
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
@Test
public void testOnline() throws Exception {
XMLModelImporter importer = new XMLModelImporter(LAZY_TEST_MODEL_FILENAME, new JDBCDBImporter(ENVIRONMENT));
try {
Database db = importer.importDatabase();
new TreeLogger().log(new DBTreeModel(db));
assertFalse(db.isSequencesImported());
List<DBSequence> sequences = db.getSequences();
assertEquals(1, sequences.size());
assertEquals("SEQ1", sequences.get(0).getName());
assertEquals(BigInteger.valueOf(1000), sequences.get(0).getStart());
assertTrue(db.isSequencesImported());
} finally {
IOUtil.close(importer);
}
}
示例8: writeBinaryFile
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
/** Creates a binary file and writes to it all content provided by the source {@link InputStream}.
* @param filePath the path of the file to save
* @param source an {@link InputStream} which provides the content to write to the file
* @param overwrite flag which indicates if an existing file may be overwritten by the operation
* @return true if a formerly existing file was overwritten.
* @throws FunctionalFailure if a file was already present and overwriting was disabled. */
@Override
public boolean writeBinaryFile(String filePath, InputStream source, boolean overwrite) {
assertWritingPermitted("writeBinaryFile()");
File.verifyFilePath(filePath);
OutputStream out = null;
try {
FileObject target = getFileObject(filePath);
boolean existedBefore = checkWritable(target, overwrite); // NOSONAR
out = target.getContent().getOutputStream();
IOUtil.transfer(source, out);
logger.debug("Wrote binary file {}", filePath);
return existedBefore;
}
catch (IOException e) {
throw new TechnicalException("Error writing text file", e);
}
finally {
IOUtil.close(out);
}
}
示例9: readBinaryFile
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
/** Reads a binary file and provides its content as an array of bytes. */
@Override
public byte[] readBinaryFile(String filePath) {
File.verifyFilePath(filePath);
if (!exists(filePath) || isDirectory(filePath)) {
throw new AutomationException("No file exists at the given file path");
}
InputStream in = null;
try {
in = getInputStreamForFile(filePath);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtil.transfer(in, out);
logger.debug("Binary file read: {}", filePath);
return out.toByteArray();
}
catch (IOException e) {
throw new TechnicalException("Error reading binary file", e);
}
finally {
IOUtil.close(in);
}
}
示例10: testReader
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
@Test
public void testReader() throws Exception {
Reader in = null;
try {
in = IOUtil.getReaderForURI("org/aludratest/content/separated/persons.csv");
WebdecsSeparatedContent contenHandler = new WebdecsSeparatedContent();
Object readerId = contenHandler.createReader(in, SepPersonData.class, ',');
assertEquals("VER1234", contenHandler.readHeader(readerId));
assertEquals(new SepPersonData("Alice", "23"), contenHandler.readRow(readerId));
assertEquals(new SepPersonData("Bob", "34"), contenHandler.readRow(readerId));
assertNull(contenHandler.readRow(readerId));
contenHandler.closeReader(readerId);
} finally {
IOUtil.close(in);
}
}
示例11: testIntegration
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testIntegration() throws Exception {
ConsumerMock consumer = new ConsumerMock(true);
context.setGlobal("cons", consumer);
DescriptorRunner runner = new DescriptorRunner("org/databene/platform/db/SequenceTableIntegrationTest.ben.xml", context);
try {
runner.run();
List<Entity> products = (List<Entity>) consumer.getProducts();
assertEquals(2, products.size());
assertEquals(createEntity("x", "id", 2000), products.get(0));
assertEquals(createEntity("x", "id", 2001), products.get(1));
} finally {
IOUtil.close(runner);
}
}
示例12: runFile
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
public static void runFile(String filename, InfoPrinter printer) throws IOException {
BeneratorMonitor.INSTANCE.reset();
MemorySensor memProfiler = MemorySensor.getInstance();
memProfiler.reset();
if (printer != null) {
printer.printLines("Running file " + filename);
BeneratorUtil.checkSystem(printer);
}
BeneratorContext context = BeneratorFactory.getInstance().createContext(IOUtil.getParentUri(filename));
DescriptorRunner runner = new DescriptorRunner(filename, context);
try {
runner.run();
} finally {
IOUtil.close(runner);
}
BeneratorUtil.logConfig("Max. committed heap size: " + new KiloFormatter(1024).format(memProfiler.getMaxCommittedHeapSize()) + "B");
}
示例13: check
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
private void check(int executionCount, boolean append, boolean deleteSources, String result) throws IOException {
File sourceFile1 = null;
File sourceFile2 = null;
File destFile = null;
Context context = new DefaultBeneratorContext();
FileJoiner joiner = new FileJoiner();
try {
sourceFile1 = createSource1();
sourceFile2 = createSource2();
destFile = File.createTempFile(prefix(), ".txt", new File("target"));
joiner.setAppend(append);
joiner.setSources(new String[] { "target" + File.separator + sourceFile1.getName(), "target" + File.separator + sourceFile2.getName() });
joiner.setDestination("target" + File.separator + destFile.getName());
joiner.setDeleteSources(deleteSources);
for (int i = 0; i < executionCount; i++)
joiner.execute(context, ErrorHandler.getDefault());
assertEquals(deleteSources, !sourceFile1.exists());
assertEquals(deleteSources, !sourceFile2.exists());
assertEquals(result, IOUtil.getContentOfURI(destFile.getAbsolutePath()));
} finally {
FileUtil.deleteIfExists(sourceFile1);
FileUtil.deleteIfExists(sourceFile2);
FileUtil.deleteIfExists(destFile);
IOUtil.close(joiner);
}
}
示例14: testDynamicSelector
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
@Test
public void testDynamicSelector() {
SequenceTableGenerator<Integer> generator = null;
try {
generator = new SequenceTableGenerator<Integer>("TT", "value", db);
// the selector makes the generator use row #1 and #2 after each other for generating id values
generator.setSelector("{'id1 = ' + (1 + (num % 2)) + ' and id2 = ' + (2 + (num % 2))}");
generator.init(context);
for (int i = 0; i < 100;) {
context.set("num", i);
assertEquals(1000 + i/2, generator.generate().intValue());
i++;
context.set("num", i);
assertEquals(2000 + i/2, generator.generate().intValue());
i++;
}
assertAvailable(generator);
} finally {
IOUtil.close(generator);
}
}
示例15: testNesting
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
@Test
public void testNesting() {
BeneratorContext context = new DefaultBeneratorContext(IOUtil.getParentUri(NESTING_TEST_FILE));
XMLSchemaDescriptorProvider provider = new XMLSchemaDescriptorProvider(NESTING_TEST_FILE, context);
try {
ComplexTypeDescriptor rootDescriptor = (ComplexTypeDescriptor) provider.getTypeDescriptor("root");
// check root
assertNotNull(rootDescriptor);
assertEquals(4, rootDescriptor.getComponents().size());
ComponentDescriptor rootAtt1 = rootDescriptor.getComponent("rootAtt1");
assertNotNull(rootAtt1);
// check c1
ComponentDescriptor c1 = rootDescriptor.getComponent("c1");
assertNotNull(c1);
// check number
ComponentDescriptor number = rootDescriptor.getComponent("number");
assertNotNull(number);
assertEquals(Long.valueOf(1), number.getMinCount().evaluate(null));
assertEquals(Long.valueOf(1), number.getMaxCount().evaluate(null));
// check c2
ComponentDescriptor c2 = rootDescriptor.getComponent("c2");
assertNotNull(c2);
} finally {
IOUtil.close(provider);
}
}