private static Object createInstance(final Class<?> clazz) { try { return clazz.newInstance(); } catch (final Exception e) { throw new MetafactureException( "Can't instantiate object of class: " + clazz, e); } }
@Override public void closeStream() { try { if (outputStream != null) { outputStream.close(); } } catch (IOException e) { throw new MetafactureException(e); } }
public XmlDecoder() { super(); try { saxReader = XMLReaderFactory.createXMLReader(); } catch (SAXException e) { throw new MetafactureException(e); } }
private void createParser(final String string) { try { jsonParser = jsonFactory.createParser(string); } catch (final IOException e) { throw new MetafactureException(e); } }
public MessageDigest getInstance() { try { return MessageDigest.getInstance(identifier); } catch (NoSuchAlgorithmException e) { throw new MetafactureException (e); } }
@Override public void process(final Reader reader) { try { saxReader.parse(new InputSource(reader)); } catch (IOException e) { throw new MetafactureException(e); } catch (SAXException e) { throw new MetafactureException(e); } }
private void ensureParentPathExists(final Path path) { final Path parentDir = path.getParent(); if (parentDir != null) { try { Files.createDirectories(parentDir); } catch (final IOException e) { throw new MetafactureException(e); } } }
@Override public void process(final T obj) { assert !closed; try { writer.write(obj.toString()); writer.append('\n'); } catch (IOException e) { throw new MetafactureException(e); } }
public void close() { try { in.close(); } catch (IOException e) { throw new MetafactureException("Error closing input stream", e); } if (file.exists()) { file.delete(); } }
private static Document createEmptyDocument() { try { return DocumentBuilderFactory.newInstance().newDocumentBuilder() .newDocument(); } catch (ParserConfigurationException e) { throw new MetafactureException(e); } }
@Override public void resetStream() { try { if (outputStream != null) { outputStream.close(); } outputStream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filename), BUFFERSIZE)); } catch (IOException e) { throw new MetafactureException(e); } }
@Override public OutputStream createCompressor(final OutputStream writeTo, final String fileName) { try { return APACHE_COMPRESSOR_FACTORY.createCompressorOutputStream( CompressorStreamFactory.GZIP, bufferStream(writeTo)); } catch (CompressorException e) { throw new MetafactureException(e); } }
private static Schema loadSchema(String schemaFile) { try { return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(getSchemaUrl(schemaFile)); } catch (SAXException e) { throw new MetafactureException(e); } }
public JsonEncoder() { try { jsonGenerator = new JsonFactory().createGenerator(writer); jsonGenerator.setRootValueSeparator(null); } catch (final IOException e) { throw new MetafactureException(e); } }
private static String getVersionInfo() { try { return ResourceUtil.loadProperties("build.properties").toString(); } catch (IOException e) { throw new MetafactureException("Failed to load build infos", e); } }
private void closeParser() { try { jsonParser.close(); } catch (final IOException e) { throw new MetafactureException(e); } }
@Override public OutputStream createCompressor(final OutputStream writeTo, final String fileName) { try { return APACHE_COMPRESSOR_FACTORY.createCompressorOutputStream( CompressorStreamFactory.BZIP2, bufferStream(writeTo)); } catch (CompressorException e) { throw new MetafactureException(e); } }
@Override public InputStream createDecompressor(final InputStream readFrom) { try { return APACHE_COMPRESSOR_FACTORY.createCompressorInputStream( CompressorStreamFactory.XZ, bufferStream(readFrom)); } catch (CompressorException e) { throw new MetafactureException(e); } } };
public void addDirectory(final File dir) { for (final File file : dir.listFiles(JAR_AND_CLASS_FILTER)) { try { addURL(file.toURI().toURL()); } catch (final MalformedURLException e) { throw new MetafactureException("Could not add " + file + " to class loader", e); } } }
private static void process(Source source, Result result) { final Transformer transformer = createTransformer(); try { transformer.transform(source, result); } catch (TransformerException e) { throw new MetafactureException(e); } }