use of org.haiku.pkg.model.Attribute in project haikudepotserver by haiku.
the class PkgImportServiceImpl method populateIconFromPayload.
private void populateIconFromPayload(ObjectContext objectContext, PkgVersion persistedPkgVersion, AttributeContext context, Attribute attribute) {
Attribute dataAttr = attribute.tryGetChildAttribute(AttributeId.DATA).orElse(null);
if (null == dataAttr) {
LOGGER.warn("the icon [{}] found for package [{}] version [{}] does not have a data attribute", AttributeId.FILE_ATTRIBUTE, persistedPkgVersion.getPkg(), persistedPkgVersion);
}
ByteSource byteSource = (ByteSource) dataAttr.getValue(context);
try {
LOGGER.info("did find {} bytes of icon data for package [{}] version [{}]", byteSource.size(), persistedPkgVersion.getPkg(), persistedPkgVersion);
} catch (IOException ignore) {
LOGGER.warn("cannot get the size of the icon payload for package [{}] version [{}]", persistedPkgVersion.getPkg(), persistedPkgVersion);
}
try (InputStream inputStream = byteSource.openStream()) {
pkgIconService.storePkgIconImage(inputStream, MediaType.getByCode(objectContext, MediaType.MEDIATYPE_HAIKUVECTORICONFILE), null, objectContext, persistedPkgVersion.getPkg().getPkgSupplement());
} catch (IOException ioe) {
throw new UncheckedIOException(ioe);
} catch (BadPkgIconException e) {
LOGGER.info("a failure has arisen loading a package icon data", e);
}
}
use of org.haiku.pkg.model.Attribute 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