use of com.google.common.io.ByteSource in project hale by halestudio.
the class MsAccessDataReaderTestSuit method createSourceTempFile.
/**
* Copies the source database to a temporary file.
*
* @throws IOException if temp file can't be created
*/
public void createSourceTempFile() throws IOException {
ByteSource source = Resources.asByteSource(MsAccessDataReaderTestSuit.class.getClassLoader().getResource(SOURCE_DB_PATH));
ByteSink dest = Files.asByteSink(getSourceTempFilePath());
source.copyTo(dest);
}
use of com.google.common.io.ByteSource in project hale by halestudio.
the class SpatiaLiteTestSuite method createSourceTempFile.
/**
* Copies the source database to a temporary file.
*
* @throws IOException if temp file can't be created
*/
public void createSourceTempFile() throws IOException {
ByteSource source = Resources.asByteSource(SpatiaLiteTestSuite.class.getResource(SOURCE_DB_LOCATION));
ByteSink dest = Files.asByteSink(new File(getSourceTempFilePath()));
source.copyTo(dest);
}
use of com.google.common.io.ByteSource in project hale by halestudio.
the class SpatiaLiteTestSuite method createTargetTempFile.
/**
* Copies the target database to a temporary file and deletes all instances
* in it.
*
* @throws IOException if temp file can't be created or instances can't be
* deleted
*/
public void createTargetTempFile() throws IOException {
ByteSource source = Resources.asByteSource(SpatiaLiteTestSuite.class.getResource(SOURCE_DB_LOCATION));
ByteSink dest = Files.asByteSink(new File(getTargetTempFilePath()));
source.copyTo(dest);
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:sqlite:" + getTargetTempFilePath());
Statement stmt = conn.createStatement();
stmt.executeUpdate("DELETE FROM " + SOUURCE_TYPE_LOCAL_NAME);
} catch (SQLException e) {
throw new IOException("Could not empty target DB", e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// ignore
}
}
}
}
use of com.google.common.io.ByteSource in project ddf by codice.
the class InMemoryProcessingFramework method storeProcessRequest.
private <T extends ProcessResourceItem> void storeProcessRequest(ProcessRequest<T> processRequest) {
LOGGER.trace("Storing update request post processing change(s)");
Map<String, ContentItem> contentItemsToUpdate = new HashMap<>();
Map<String, Metacard> metacardsToUpdate = new HashMap<>();
List<TemporaryFileBackedOutputStream> tfbosToCleanUp = new ArrayList<>();
for (T item : processRequest.getProcessItems()) {
if (item.getProcessResource() == null && item.isMetacardModified()) {
metacardsToUpdate.put(item.getMetacard().getId(), item.getMetacard());
}
final ProcessResource processResource = item.getProcessResource();
TemporaryFileBackedOutputStream tfbos = null;
if (processResource != null && processResource.isModified() && !contentItemsToUpdate.containsKey(getContentItemKey(item.getMetacard(), processResource))) {
try {
tfbos = new TemporaryFileBackedOutputStream();
long numberOfBytes = IOUtils.copyLarge(processResource.getInputStream(), tfbos);
LOGGER.debug("Copied {} bytes to TemporaryFileBackedOutputStream.", numberOfBytes);
ByteSource byteSource = tfbos.asByteSource();
ContentItem contentItem = new ContentItemImpl(item.getMetacard().getId(), processResource.getQualifier(), byteSource, processResource.getMimeType(), processResource.getName(), processResource.getSize(), item.getMetacard());
contentItemsToUpdate.put(getContentItemKey(item.getMetacard(), processResource), contentItem);
tfbosToCleanUp.add(tfbos);
} catch (IOException | RuntimeException e) {
LOGGER.debug("Unable to store process request", e);
if (tfbos != null) {
close(tfbos);
}
}
}
}
storeContentItemUpdates(contentItemsToUpdate, processRequest.getProperties());
storeMetacardUpdates(metacardsToUpdate, processRequest.getProperties());
closeTfbos(tfbosToCleanUp);
}
use of com.google.common.io.ByteSource in project ddf by codice.
the class TestTemporaryFileBackedOutputStream method testWriteByte.
@Test
public void testWriteByte() throws IOException {
temporaryFileBackedOutputStream.write(TEST_BYTE);
ByteSource byteSource = temporaryFileBackedOutputStream.asByteSource();
assertThat(byteSource.read(), is(TEST_BYTE_ARRAY));
}
Aggregations