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());
}
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);
}
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) {
}
}
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);
}
}
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);
}
}
Aggregations