use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project BWAPI4J by OpenBW.
the class DummyDataUtils method readMultiLinesAsStringTokensFromArchiveFile.
public static List<List<String>> readMultiLinesAsStringTokensFromArchiveFile(final String archiveFilename, final String mapHash, final String regex) throws IOException {
final InputStream inputStream = createInputStreamForDummyDataSet(archiveFilename);
final String mapShortHash = determineMapShortHash(mapHash);
try (final ArchiveInputStream tarIn = new TarArchiveInputStream(new BZip2CompressorInputStream(inputStream));
final BufferedReader buffer = new BufferedReader(new InputStreamReader(tarIn))) {
final ArchiveEntry nextEntry = getArchiveEntry(tarIn, mapShortHash);
Assert.assertNotNull(nextEntry);
final List<List<String>> data = new ArrayList<>();
String line;
while ((line = buffer.readLine()) != null) {
if (line.isEmpty()) {
continue;
}
final String[] tokens = line.split(regex);
final List<String> strTokens = new ArrayList<>();
for (final String token : tokens) {
final String tokenTrimmed = token.trim();
if (tokenTrimmed.isEmpty()) {
continue;
}
strTokens.add(tokenTrimmed);
}
data.add(strTokens);
}
int valuesReadCount = 0;
for (final List<String> list : data) {
valuesReadCount += list.size();
}
logger.debug("Read " + valuesReadCount + " values from " + archiveFilename);
return data;
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project BWAPI4J by OpenBW.
the class DummyDataUtils method readMultiLineIntegerArraysFromArchiveFile.
public static List<List<Integer>> readMultiLineIntegerArraysFromArchiveFile(final String archiveFilename, final String mapHash, final String regex) throws IOException {
final InputStream inputStream = createInputStreamForDummyDataSet(archiveFilename);
final String mapShortHash = determineMapShortHash(mapHash);
try (final ArchiveInputStream tarIn = new TarArchiveInputStream(new BZip2CompressorInputStream(inputStream));
final BufferedReader buffer = new BufferedReader(new InputStreamReader(tarIn))) {
final ArchiveEntry nextEntry = getArchiveEntry(tarIn, mapShortHash);
Assert.assertNotNull(nextEntry);
final List<List<Integer>> data = new ArrayList<>();
String line;
while ((line = buffer.readLine()) != null) {
if (line.isEmpty()) {
continue;
}
final String[] tokens = line.split(regex);
final List<Integer> intTokens = new ArrayList<>();
for (final String token : tokens) {
final String tokenTrimmed = token.trim();
if (tokenTrimmed.isEmpty()) {
continue;
}
int intToken = Integer.parseInt(tokenTrimmed);
intTokens.add(intToken);
}
data.add(intTokens);
}
int valuesReadCount = 0;
for (final List<Integer> list : data) {
valuesReadCount += list.size();
}
logger.debug("Read " + valuesReadCount + " values from " + archiveFilename);
return data;
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project BWAPI4J by OpenBW.
the class DummyDataUtils method readIntegerArrayFromArchiveFile.
public static int[] readIntegerArrayFromArchiveFile(final String archiveFilename, final String mapHash, final String regex) throws IOException {
final InputStream inputStream = createInputStreamForDummyDataSet(archiveFilename);
try (final ArchiveInputStream tarIn = new TarArchiveInputStream(new BZip2CompressorInputStream(inputStream));
final BufferedReader buffer = new BufferedReader(new InputStreamReader(tarIn))) {
final String mapShortHash = determineMapShortHash(mapHash);
final ArchiveEntry nextEntry = getArchiveEntry(tarIn, mapShortHash);
Assert.assertNotNull(nextEntry);
final int[] read = buffer.lines().flatMap(line -> (Stream<String>) Stream.of(line.split(regex))).map(String::trim).mapToInt(Integer::parseInt).toArray();
logger.debug("Read " + read.length + " values from " + archiveFilename);
return read;
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project zalenium by zalando.
the class DockerSeleniumRemoteProxy method copyVideos.
@SuppressWarnings("ResultOfMethodCallIgnored")
@VisibleForTesting
void copyVideos(final String containerId) {
boolean videoWasCopied = false;
TarArchiveInputStream tarStream = new TarArchiveInputStream(containerClient.copyFiles(containerId, "/videos/"));
try {
TarArchiveEntry entry;
while ((entry = tarStream.getNextTarEntry()) != null) {
if (entry.isDirectory()) {
continue;
}
String fileExtension = entry.getName().substring(entry.getName().lastIndexOf('.'));
testInformation.setFileExtension(fileExtension);
File videoFile = new File(testInformation.getVideoFolderPath(), testInformation.getFileName());
File parent = videoFile.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
OutputStream outputStream = new FileOutputStream(videoFile);
IOUtils.copy(tarStream, outputStream);
outputStream.close();
videoWasCopied = true;
LOGGER.info(String.format("%s Video file copied to: %s/%s", getId(), testInformation.getVideoFolderPath(), testInformation.getFileName()));
}
} catch (IOException e) {
// This error happens in k8s, but the file is ok, nevertheless the size is not accurate
boolean isPipeClosed = e.getMessage().toLowerCase().contains("pipe closed");
if (ContainerFactory.getIsKubernetes().get() && isPipeClosed) {
LOGGER.info(String.format("%s Video file copied to: %s/%s", getId(), testInformation.getVideoFolderPath(), testInformation.getFileName()));
} else {
LOGGER.warn(getId() + " Error while copying the video", e);
}
ga.trackException(e);
} finally {
if (!videoWasCopied) {
testInformation.setVideoRecorded(false);
}
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project syndesis by syndesisio.
the class ProjectGeneratorTest method generate.
// *****************************
// Helpers
// *****************************
private Path generate(Integration integration, ProjectGeneratorConfiguration generatorConfiguration, TestResourceManager resourceManager) throws IOException {
final IntegrationProjectGenerator generator = new ProjectGenerator(generatorConfiguration, resourceManager, getMavenProperties());
try (InputStream is = generator.generate(integration)) {
Path ret = testFolder.newFolder("integration-project").toPath();
try (TarArchiveInputStream tis = new TarArchiveInputStream(is)) {
TarArchiveEntry tarEntry = tis.getNextTarEntry();
// tarIn is a TarArchiveInputStream
while (tarEntry != null) {
// create a file with the same name as the tarEntry
File destPath = new File(ret.toFile(), tarEntry.getName());
if (tarEntry.isDirectory()) {
destPath.mkdirs();
} else {
destPath.getParentFile().mkdirs();
destPath.createNewFile();
try (BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath))) {
IOUtils.copy(tis, bout);
}
}
tarEntry = tis.getNextTarEntry();
}
}
return ret;
}
}
Aggregations