use of org.molgenis.emx2.MolgenisException in project molgenis-emx2 by molgenis.
the class TestReadWriteStores method testExcelStore.
@Test
public void testExcelStore() throws IOException {
Path tmp = Files.createTempDirectory(null);
try {
Path excelFile = tmp.resolve("test.xlsx");
System.out.println("defined excel file " + excelFile);
TableStoreForXlsxFile store = new TableStoreForXlsxFile(excelFile);
executeTest(store);
} catch (MolgenisException e) {
e.printStackTrace();
} finally {
Files.walk(tmp).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}
if (Files.exists(tmp))
throw new RuntimeException("TMP directory " + tmp + " not deleted. This should never happen.");
}
use of org.molgenis.emx2.MolgenisException in project molgenis-emx2 by molgenis.
the class TestReadWriteStores method testCsvZipStore.
@Test
public void testCsvZipStore() throws IOException {
Path tmp = Files.createTempDirectory(null);
try {
Path zipFile = tmp.resolve("test.zip");
System.out.println("defined zip file " + zipFile);
TableStoreForCsvInZipFile store = new TableStoreForCsvInZipFile(zipFile);
executeTest(store);
} catch (MolgenisException e) {
e.printStackTrace();
} finally {
Files.walk(tmp).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}
if (Files.exists(tmp))
throw new RuntimeException("TMP directory " + tmp + " not deleted. This should never happen.");
}
use of org.molgenis.emx2.MolgenisException in project molgenis-emx2 by molgenis.
the class TableStoreForCsvFilesDirectory method writeFile.
public void writeFile(String filePath, byte[] contents) {
if (contents != null && contents.length > 0) {
try {
Path dir = directoryPath.resolve("_files");
if (!Files.exists(dir)) {
Files.createDirectories(dir);
}
Path file = directoryPath.resolve(filePath);
try (OutputStream out = Files.newOutputStream(file)) {
out.write(contents);
out.flush();
}
} catch (Exception e) {
throw new MolgenisException("Writing of file " + filePath + " failed: ", e);
}
}
}
use of org.molgenis.emx2.MolgenisException in project molgenis-emx2 by molgenis.
the class TableStoreForCsvInZipFile method create.
private void create() {
Map<String, String> env = new HashMap<>();
env.put("create", "true");
final URI zipUri = URI.create("jar:" + zipFilePath.toUri());
try {
FileSystem zipfs = FileSystems.newFileSystem(zipUri, env, null);
zipfs.close();
} catch (IOException ioe) {
throw new MolgenisException("Import failed", ioe);
}
}
use of org.molgenis.emx2.MolgenisException in project molgenis-emx2 by molgenis.
the class TableStoreForCsvInZipFile method getBinaryFileWrapper.
@Override
public BinaryFileWrapper getBinaryFileWrapper(String name) {
try (ZipFile zf = new ZipFile(zipFilePath.toFile())) {
ZipEntry entry = getEntry(zf, name);
if (entry != null) {
String contentType = URLConnection.guessContentTypeFromName(entry.getName());
InputStream contents = zf.getInputStream(entry);
return new BinaryFileWrapper(contentType, entry.getName(), contents.readAllBytes());
} else {
throw new MolgenisException("Import failed: file '" + name + "' not found in file.");
}
} catch (Exception e) {
throw new MolgenisException("Import failed: file '" + name + "' resulted in error: ", e);
}
}
Aggregations