use of org.haiku.pkg.AttributeContext in project haikudepotserver by haiku.
the class PkgImportServiceImpl method populateIconFromPayload.
private void populateIconFromPayload(ObjectContext objectContext, PkgVersion persistedPkgVersion, HpkgFileExtractor hpkgFileExtractor) {
AttributeContext context = hpkgFileExtractor.getTocContext();
List<Attribute> iconAttrs = HpkgHelper.findIconAttributesFromExecutableDirEntries(context, hpkgFileExtractor.getToc());
switch(iconAttrs.size()) {
case 0:
LOGGER.info("package [{}] version [{}] has no icons", persistedPkgVersion.getPkg(), persistedPkgVersion);
break;
case 1:
populateIconFromPayload(objectContext, persistedPkgVersion, context, Iterables.getFirst(iconAttrs, null));
break;
default:
LOGGER.info("package [{}] version [{}] has {} icons --> ambiguous so will not load any", persistedPkgVersion.getPkg(), persistedPkgVersion, iconAttrs.size());
break;
}
}
use of org.haiku.pkg.AttributeContext 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