org.infrastructurebuilder.data.IBMetadataUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ibdata-api Show documentation
Show all versions of ibdata-api Show documentation
APIs for dealing with data streams
The newest version!
/**
* Copyright © 2019 admin ([email protected])
*
* Licensed 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.
*/
package org.infrastructurebuilder.data;
import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;
import static javax.xml.parsers.DocumentBuilderFactory.newInstance;
import static org.infrastructurebuilder.data.IBDataException.cet;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.infrastructurebuilder.data.model.DataStream;
import org.infrastructurebuilder.data.model.DataStreamStructuredMetadata;
import org.infrastructurebuilder.util.artifacts.Checksum;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class IBMetadataUtils {
public final static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
public final static Supplier builderSupplier = () -> cet
.withReturningTranslation(() -> factory.newDocumentBuilder());
public final static Supplier emptyDocumentSupplier = () -> builderSupplier.get().newDocument();
private final static TransformerFactory tf = TransformerFactory.newInstance();
private final static Supplier tfSupplier = () -> {
return cet.withReturningTranslation(() -> tf.newTransformer());
};
/**
* Map an object to a W3C Document. If null, returns an empty Document
*/
public final static Function