Search in sources :

Example 6 with Attribute

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);
    }
}
Also used : BadPkgIconException(org.haiku.haikudepotserver.pkg.model.BadPkgIconException) Attribute(org.haiku.pkg.model.Attribute) InputStream(java.io.InputStream) ByteSource(com.google.common.io.ByteSource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 7 with Attribute

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);
}
Also used : AttributeContext(org.haiku.pkg.AttributeContext) Attribute(org.haiku.pkg.model.Attribute) ByteSource(com.google.common.io.ByteSource) HpkgFileExtractor(org.haiku.pkg.HpkgFileExtractor) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

Attribute (org.haiku.pkg.model.Attribute)7 ByteSource (com.google.common.io.ByteSource)4 Test (org.junit.jupiter.api.Test)4 File (java.io.File)3 IOException (java.io.IOException)2 AttributeContext (org.haiku.pkg.AttributeContext)2 IntAttribute (org.haiku.pkg.model.IntAttribute)2 Preconditions (com.google.common.base.Preconditions)1 HashCode (com.google.common.hash.HashCode)1 Hashing (com.google.common.hash.Hashing)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 Assertions (org.fest.assertions.Assertions)1 BadPkgIconException (org.haiku.haikudepotserver.pkg.model.BadPkgIconException)1 HpkException (org.haiku.pkg.HpkException)1