Search in sources :

Example 91 with UncheckedIOException

use of java.io.UncheckedIOException in project core-ng-project by neowu.

the class PEM method fromPEM.

public static byte[] fromPEM(String pemContent) {
    StringBuilder content = new StringBuilder();
    try (BufferedReader reader = new BufferedReader(new StringReader(pemContent))) {
        while (true) {
            String line = reader.readLine();
            if (line == null)
                break;
            if (line.startsWith("-----"))
                continue;
            content.append(line.replaceAll("\n", "").replaceAll("\r", ""));
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return Encodings.decodeBase64(content.toString());
}
Also used : BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 92 with UncheckedIOException

use of java.io.UncheckedIOException in project GMM by Katharsas.

the class XMLService method serialize.

@Override
public synchronized void serialize(Object object, Path path) {
    final String xml = xmlEncodingHeader + xstream.toXML(object);
    byte[] bytes;
    try {
        bytes = xml.getBytes(xmlEncoding);
    } catch (final UnsupportedEncodingException e) {
        throw new UncheckedIOException(e);
    }
    fileService.createFile(path, bytes);
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) UncheckedIOException(java.io.UncheckedIOException)

Example 93 with UncheckedIOException

use of java.io.UncheckedIOException in project GMM by Katharsas.

the class XMLServiceTest method testInvalidArguments.

@Test
public void testInvalidArguments() {
    final Path file = testFolder.resolve("null_test_file.xml");
    xmlService.serialize(null, file);
    final Object nullObject = xmlService.deserializeAll(file, Object.class);
    assertEquals(null, nullObject);
    try {
        xmlService.deserialize(file.resolve("does_not_exist"), Object.class);
        fail();
    } catch (final UncheckedIOException e) {
    }
    try {
        xmlService.deserializeAll(file.resolve("does_not_exist"), Object.class);
        fail();
    } catch (final UncheckedIOException e) {
    }
    try {
        xmlService.deserialize(null, Object.class);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        xmlService.deserializeAll(null, Object.class);
        fail();
    } catch (final NullPointerException e) {
    }
}
Also used : Path(java.nio.file.Path) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.Test)

Example 94 with UncheckedIOException

use of java.io.UncheckedIOException in project GMM by Katharsas.

the class ModelTaskService method writePreview.

public void writePreview(ModelTask task, String version, OutputStream target) {
    final String modelName = version + ".json";
    final Path path = config.assetPreviews().resolve(task.getAssetName().getKey()).resolve(modelName);
    try (FileInputStream fis = new FileInputStream(path.toFile())) {
        IOUtils.copy(fis, target);
    } catch (final IOException e) {
        throw new UncheckedIOException("Could not write preview file from '" + path.toString() + "' to stream!", e);
    }
}
Also used : Path(java.nio.file.Path) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) FileInputStream(java.io.FileInputStream)

Example 95 with UncheckedIOException

use of java.io.UncheckedIOException in project GMM by Katharsas.

the class FtlRenderer method renderTemplate.

/**
 * @param fileName - Name of template file without file extension.
 */
private void renderTemplate(String fileName, ModelMap model, StringWriter target) {
    try {
        final String fileExtension = ".html.ftl";
        config.getTemplate(fileName + fileExtension).process(model, target);
    } catch (final TemplateException e) {
        throw new RuntimeException(e);
    } catch (final IOException e) {
        throw new UncheckedIOException("Couldn't retrieve Freemarker template file '" + fileName + "'!", e);
    }
}
Also used : TemplateException(freemarker.template.TemplateException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

UncheckedIOException (java.io.UncheckedIOException)826 IOException (java.io.IOException)786 File (java.io.File)109 Path (java.nio.file.Path)106 ArrayList (java.util.ArrayList)70 InputStream (java.io.InputStream)58 Map (java.util.Map)58 List (java.util.List)55 HashMap (java.util.HashMap)44 Test (org.junit.Test)38 Files (java.nio.file.Files)37 Collectors (java.util.stream.Collectors)37 Stream (java.util.stream.Stream)31 URL (java.net.URL)29 StringWriter (java.io.StringWriter)27 CursorContext (org.neo4j.io.pagecache.context.CursorContext)25 FileInputStream (java.io.FileInputStream)23 HashSet (java.util.HashSet)23 PageCursor (org.neo4j.io.pagecache.PageCursor)22 Optional (java.util.Optional)21