All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.xmlgraphics.xmp.XMPPacketParser Maven / Gradle / Ivy

There is a newer version: 2.8_1
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id: XMPPacketParser.java 1681108 2015-05-22 13:26:12Z ssteiner $ */

package org.apache.xmlgraphics.xmp;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;

import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;

/**
 * This class is a parser for XMP packets. By default, it tries to locate the first XMP packet
 * it finds and parses it.
 * 

* Important: Before you use this class to look for an XMP packet in some random file, please read * the chapter on "Scanning Files for XMP Packets" in the XMP specification! */ public final class XMPPacketParser { private XMPPacketParser() { } private static final byte[] PACKET_HEADER; private static final byte[] PACKET_HEADER_END; private static final byte[] PACKET_TRAILER; static { try { PACKET_HEADER = "".getBytes("US-ASCII"); PACKET_TRAILER = "= 0) { if (b == match[found]) { found++; if (found == len) { return true; } } else { if (out != null) { if (found > 0) { out.write(match, 0, found); } out.write(b); } found = 0; } } return false; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy