Example usage for java.util.jar Attributes Attributes

List of usage examples for java.util.jar Attributes Attributes

Introduction

In this page you can find the example usage for java.util.jar Attributes Attributes.

Prototype

public Attributes() 

Source Link

Document

Constructs a new, empty Attributes object with default size.

Usage

From source file:com.aimluck.eip.project.ProjectTaskSimpleSelectData.java

/**
 * ??/*w w w . jav a  2  s.c  o  m*/
 * 
 * @return 
 */
@Override
protected Attributes getColumnMap() {
    Attributes map = new Attributes();
    map.putValue("task_name", "task_name");
    map.putValue("progress_rate", "progress_rate");
    return map;
}

From source file:com.taobao.android.builder.tools.sign.LocalSignedJarBuilder.java

/**
 * Adds an entry to the output jar, and write its content from the {@link InputStream}
 *
 * @param input The input stream from where to write the entry content.
 * @param entry the entry to write in the jar.
 * @throws IOException/*from   w  ww  .j a  v a2 s  . co m*/
 */
private void writeEntry(InputStream input, JarEntry entry) throws IOException {
    // add the entry to the jar archive
    mOutputJar.putNextEntry(entry);

    // read the content of the entry from the input stream, and write it into the archive.
    int count;
    while ((count = input.read(mBuffer)) != -1) {
        mOutputJar.write(mBuffer, 0, count);

        // update the digest
        if (mMessageDigest != null) {
            mMessageDigest.update(mBuffer, 0, count);
        }
    }

    // close the entry for this file
    mOutputJar.closeEntry();

    if (mManifest != null) {
        // update the manifest for this entry.
        Attributes attr = mManifest.getAttributes(entry.getName());
        if (attr == null) {
            attr = new Attributes();
            mManifest.getEntries().put(entry.getName(), attr);
        }
        attr.putValue(DIGEST_ATTR, new String(Base64.encode(mMessageDigest.digest()), "ASCII"));
    }
}

From source file:com.aimluck.eip.project.ProjectTaskSelectData.java

/**
 * ??//ww w  .  j  a  v  a  2 s . com
 *
 * @return 
 */
@Override
protected Attributes getColumnMap() {
    Attributes map = new Attributes();
    map.putValue("task_name", "task_name");
    map.putValue("tracker", "tracker");
    map.putValue("status", "status");
    map.putValue("workload", "workload");
    map.putValue("plan_workload", "plan_workload");
    map.putValue("start_plan_date", "start_plan_date");
    map.putValue("end_plan_date", "end_plan_date");
    map.putValue("progress_rate", "progress_rate");
    return map;
}

From source file:com.taobao.android.builder.tools.sign.LocalSignedJarBuilder.java

/**
 * Writes a .SF file with a digest to the manifest.
 *//*from  ww  w  .  j a v a  2 s.c om*/
private void writeSignatureFile(OutputStream out) throws IOException, GeneralSecurityException {
    Manifest sf = new Manifest();
    Attributes main = sf.getMainAttributes();
    main.putValue("Signature-Version", "1.0");
    main.putValue("Created-By", "1.0 (Android)");

    MessageDigest md = MessageDigest.getInstance(DIGEST_ALGORITHM);
    PrintStream print = new PrintStream(new DigestOutputStream(new ByteArrayOutputStream(), md), true,
            SdkConstants.UTF_8);

    // Digest of the entire manifest
    mManifest.write(print);
    print.flush();
    main.putValue(DIGEST_MANIFEST_ATTR, new String(Base64.encode(md.digest()), "ASCII"));

    Map<String, Attributes> entries = mManifest.getEntries();
    for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
        // Digest of the manifest stanza for this entry.
        print.print("Name: " + entry.getKey() + "\r\n");
        for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
            print.print(att.getKey() + ": " + att.getValue() + "\r\n");
        }
        print.print("\r\n");
        print.flush();

        Attributes sfAttr = new Attributes();
        sfAttr.putValue(DIGEST_ATTR, new String(Base64.encode(md.digest()), "ASCII"));
        sf.getEntries().put(entry.getKey(), sfAttr);
    }
    CountOutputStream cout = new CountOutputStream(out);
    sf.write(cout);

    // A bug in the java.util.jar implementation of Android platforms
    // up to version 1.6 will cause a spurious IOException to be thrown
    // if the length of the signature file is a multiple of 1024 bytes.
    // As a workaround, add an extra CRLF in this case.
    if ((cout.size() % 1024) == 0) {
        cout.write('\r');
        cout.write('\n');
    }
}

From source file:com.aimluck.eip.msgboard.MsgboardTopicSelectData.java

/**
 * @return//from  w  w w. j  a v a 2  s .c om
 *
 */
@Override
protected Attributes getColumnMap() {
    Attributes map = new Attributes();
    map.putValue("topic_name", EipTMsgboardTopic.TOPIC_NAME_PROPERTY);
    map.putValue("update_date", EipTMsgboardTopic.UPDATE_DATE_PROPERTY);
    map.putValue("category", EipTMsgboardCategory.CATEGORY_ID_PK_COLUMN);
    map.putValue("category_name", EipTMsgboardTopic.EIP_TMSGBOARD_CATEGORY_PROPERTY + "."
            + EipTMsgboardCategory.CATEGORY_NAME_PROPERTY);
    map.putValue("owner_name", EipTMsgboardTopic.OWNER_ID_PROPERTY);
    map.putValue("update_user", EipTMsgboardTopic.UPDATE_USER_ID_PROPERTY);

    return map;
}

From source file:com.liferay.portal.plugin.PluginPackageUtil.java

private PluginPackage _readPluginPackageServletManifest(ServletContext servletContext) throws IOException {
    Attributes attributes = null;

    String servletContextName = servletContext.getServletContextName();

    InputStream inputStream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF");

    if (inputStream != null) {
        Manifest manifest = new Manifest(inputStream);

        attributes = manifest.getMainAttributes();
    } else {//ww  w  . j  av  a 2  s  . c  o m
        attributes = new Attributes();
    }

    String artifactGroupId = attributes.getValue("Implementation-Vendor-Id");

    if (Validator.isNull(artifactGroupId)) {
        artifactGroupId = attributes.getValue("Implementation-Vendor");
    }

    if (Validator.isNull(artifactGroupId)) {
        artifactGroupId = GetterUtil.getString(attributes.getValue("Bundle-Vendor"), servletContextName);
    }

    String artifactId = attributes.getValue("Implementation-Title");

    if (Validator.isNull(artifactId)) {
        artifactId = GetterUtil.getString(attributes.getValue("Bundle-Name"), servletContextName);
    }

    String version = attributes.getValue("Implementation-Version");

    if (Validator.isNull(version)) {
        version = GetterUtil.getString(attributes.getValue("Bundle-Version"), Version.UNKNOWN);
    }

    if (version.equals(Version.UNKNOWN) && _log.isWarnEnabled()) {
        _log.warn("Plugin package on context " + servletContextName
                + " cannot be tracked because this WAR does not contain a "
                + "liferay-plugin-package.xml file");
    }

    PluginPackage pluginPackage = new PluginPackageImpl(artifactGroupId + StringPool.SLASH + artifactId
            + StringPool.SLASH + version + StringPool.SLASH + "war");

    pluginPackage.setName(artifactId);

    String shortDescription = attributes.getValue("Bundle-Description");

    if (Validator.isNotNull(shortDescription)) {
        pluginPackage.setShortDescription(shortDescription);
    }

    String pageURL = attributes.getValue("Bundle-DocURL");

    if (Validator.isNotNull(pageURL)) {
        pluginPackage.setPageURL(pageURL);
    }

    return pluginPackage;
}

From source file:com.facebook.buck.jvm.java.DefaultJavaLibraryIntegrationTest.java

@Test
public void shouldIncludeUserSuppliedManifestIfProvided() throws IOException {
    setUpProjectWorkspaceForScenario("manifest");

    Manifest m = new Manifest();
    Attributes attrs = new Attributes();
    attrs.putValue("Data", "cheese");
    m.getEntries().put("Example", attrs);
    m.write(System.out);/*w  w  w  . j a  v  a2s .co m*/

    Path path = workspace.buildAndReturnOutput("//:library");

    try (InputStream is = Files.newInputStream(path); JarInputStream jis = new JarInputStream(is)) {
        Manifest manifest = jis.getManifest();
        String value = manifest.getEntries().get("Example").getValue("Data");
        assertEquals("cheese", value);
    }
}

From source file:org.apache.felix.deploymentadmin.itest.util.DPSigner.java

private Attributes getDigestAttributes(byte[] rawData) throws IOException {
    Attributes attrs = new Attributes();
    attrs.putValue(m_digestAlg + "-Digest", calculateDigest(rawData));
    return attrs;
}

From source file:org.echocat.nodoodle.transport.HandlerPacker.java

protected Manifest createManifest(String dataFileName, Collection<String> dependencyFileNames) {
    if (dataFileName == null) {
        throw new NullPointerException();
    }/*w w  w. j a  v a  2s.  c  om*/
    if (dependencyFileNames == null) {
        throw new NullPointerException();
    }
    final Manifest manifest = new Manifest();
    final Attributes mainAttributes = manifest.getMainAttributes();
    mainAttributes.put(MANIFEST_VERSION, "1.0");
    mainAttributes.put(new Attributes.Name("Created-By"), getSmappserVersionString());
    mainAttributes.put(CLASS_PATH, StringUtils.join(dependencyFileNames, ' '));

    final Attributes extensionAttributes = new Attributes();
    extensionAttributes.put(MANIFEST_DATE_FILE, dataFileName);
    manifest.getEntries().put(MANIFEST_EXTENSION_NAME, extensionAttributes);
    return manifest;
}

From source file:org.kepler.kar.KAREntry.java

/**
 * create a karentry from a jarentry/* w  w  w.j  a v  a 2  s . c o m*/
 */
public KAREntry(JarEntry je) {
    super(je);
    try {
        Attributes atts = je.getAttributes();
        if (atts == null) {
            _attributes = new Attributes();
        } else {
            _attributes = atts;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (isDebugging)
        log.debug(this.debugString());
}