File: XmpWriter.java

package info (click to toggle)
libmetadata-extractor-java 2.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 6,416 kB
  • sloc: java: 35,343; xml: 200; sh: 11; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.drew.metadata.xmp;

import java.io.OutputStream;

import com.adobe.xmp.XMPException;
import com.adobe.xmp.XMPMeta;
import com.adobe.xmp.XMPMetaFactory;
import com.adobe.xmp.options.SerializeOptions;
import com.drew.metadata.Metadata;

public class XmpWriter
{
    /**
     * Serializes the XmpDirectory component of <code>Metadata</code> into an <code>OutputStream</code>
     * @param os Destination for the xmp data
     * @param data populated metadata
     * @return serialize success
     */
    public static boolean write(OutputStream os, Metadata data)
    {
        XmpDirectory dir = data.getFirstDirectoryOfType(XmpDirectory.class);
        if (dir == null)
            return false;
        XMPMeta meta = dir.getXMPMeta();
        try
        {
            SerializeOptions so = new SerializeOptions().setOmitPacketWrapper(true);
            XMPMetaFactory.serialize(meta, os, so);
        }
        catch (XMPException e)
        {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}