/*
* 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.itextpdf;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import br.net.woodstock.rockframework.core.utils.Arrays;
import br.net.woodstock.rockframework.core.utils.IO;
import br.net.woodstock.rockframework.document.DocumentException;
import com.itextpdf.text.pdf.PdfReader;
abstract class IText {
private IText() {
//
}
public static PdfReader read(final Object value) throws IOException {
byte[] bytes = null;
if (Arrays.isArrayOfType(value, byte.class)) {
bytes = (byte[]) value;
} else if (value instanceof InputStream) {
bytes = IO.toByteArray((InputStream) value);
}
if (bytes == null) {
throw new DocumentException("Invalid PDF source type");
}
PdfReader reader = new PdfReader(bytes);
return reader;
}
public static Charset getCharset(final Object value) {
if (value instanceof Charset) {
return (Charset) value;
}
if (value instanceof String) {
return Charset.forName((String) value);
}
return Charset.defaultCharset();
}
}