/*
* This file is part of rockframework.
*
* rockframework is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* rockframework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>;.
*/
package br.net.woodstock.rockframework.document.pdf.pdfbox;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import br.net.woodstock.rockframework.core.utils.Arrays;
import br.net.woodstock.rockframework.document.DocumentException;
abstract class PDFBox {
private PDFBox() {
//
}
public static PDFParser read(final Object value) throws IOException {
InputStream inputStream = null;
if (Arrays.isArrayOfType(value, byte.class)) {
inputStream = new ByteArrayInputStream((byte[]) value);
} else if (value instanceof InputStream) {
inputStream = (InputStream) value;
}
if (inputStream == null) {
throw new DocumentException("Invalid PDF source type");
}
PDFParser reader = new PDFParser(inputStream);
return reader;
}
public static PDDocument load(final Object value) throws IOException {
InputStream inputStream = null;
if (Arrays.isArrayOfType(value, byte.class)) {
inputStream = new ByteArrayInputStream((byte[]) value);
} else if (value instanceof InputStream) {
inputStream = (InputStream) value;
}
if (inputStream == null) {
throw new DocumentException("Invalid PDF source type");
}
PDDocument document = PDDocument.load(inputStream);
return document;
}
public static InputStream toInputStream(final Object value) {
InputStream inputStream = null;
if (Arrays.isArrayOfType(value, byte.class)) {
inputStream = new ByteArrayInputStream((byte[]) value);
} else if (value instanceof InputStream) {
inputStream = (InputStream) value;
}
return inputStream;
}
}