use of org.haiku.pkg.HpkgFileExtractor in project haikudepotserver by haiku.
the class PkgImportServiceImpl method populateFromPayload.
private void populateFromPayload(ObjectContext objectContext, PkgVersion persistedPkgVersion, URL url) {
File temporaryFile = null;
try {
String prefix = persistedPkgVersion.getPkg().getName() + "_" + RandomStringUtils.randomAlphabetic(3) + "_";
// ^ need to ensure minimum length of the prefix
temporaryFile = File.createTempFile(prefix, ".hpkg");
try {
urlHelperService.transferPayloadToFile(url, temporaryFile);
} catch (IOException ioe) {
// if we can't download then don't stop the entire import process - just log and carry on.
LOGGER.warn("unable to download from the url [{}] --> [{}]; will ignore", url, temporaryFile);
return;
}
if (null == persistedPkgVersion.getPayloadLength() || persistedPkgVersion.getPayloadLength() != temporaryFile.length()) {
persistedPkgVersion.setPayloadLength(temporaryFile.length());
LOGGER.info("recording new length for [{}] version [{}] of {}bytes", persistedPkgVersion.getPkg(), persistedPkgVersion, temporaryFile.length());
}
// more complex is the capture of the data in the parsed payload data.
HpkgFileExtractor hpkgFileExtractor;
try {
hpkgFileExtractor = new HpkgFileExtractor(temporaryFile);
} catch (Throwable th) {
// if it is not possible to parse the HPKG then log and carry on.
LOGGER.warn("unable to parse the payload from [{}]", url, th);
return;
}
populateIconFromPayload(objectContext, persistedPkgVersion, hpkgFileExtractor);
} catch (IOException ioe) {
throw new UncheckedIOException(ioe);
} finally {
if (null != temporaryFile && temporaryFile.exists()) {
if (temporaryFile.delete()) {
LOGGER.debug("did delete the temporary file");
} else {
LOGGER.error("unable to delete the temporary file [{}]", temporaryFile);
}
}
}
}
use of org.haiku.pkg.HpkgFileExtractor in project haikudepotserver by haiku.
the class AttributeDumpTool method runHpkg.
private void runHpkg() throws IOException {
try (HpkgFileExtractor hpkgFileExtractor = new HpkgFileExtractor(hpkFile);
OutputStreamWriter streamWriter = new OutputStreamWriter(System.out);
AttributeWriter attributeWriter = new AttributeWriter(streamWriter)) {
writeHeader(streamWriter, "package attributes");
attributeWriter.write(hpkgFileExtractor.getPackageAttributesIterator());
writeHeader(streamWriter, "toc");
attributeWriter.write(hpkgFileExtractor.getTocIterator());
attributeWriter.flush();
}
}
use of org.haiku.pkg.HpkgFileExtractor in project haikudepotserver by haiku.
the class HpkgHelperTest method testFindIconAttributesFromAppExecutableDirEntries.
@Test
public void testFindIconAttributesFromAppExecutableDirEntries() throws Exception {
// GIVEN
File file = prepareTestFile(RESOURCE_TEST);
HpkgFileExtractor fileExtractor = new HpkgFileExtractor(file);
AttributeContext tocContext = fileExtractor.getTocContext();
// WHEN
List<Attribute> attributes = HpkgHelper.findIconAttributesFromExecutableDirEntries(tocContext, fileExtractor.getToc());
// THEN
Assertions.assertThat(attributes).hasSize(1);
Attribute iconA = Iterables.getOnlyElement(attributes);
Attribute iconDataA = iconA.getChildAttribute(AttributeId.DATA);
ByteSource byteSource = (ByteSource) iconDataA.getValue(tocContext);
byte[] data = byteSource.read();
Assertions.assertThat(data).hasSize(544);
assertIsHvif(data);
}
Aggregations