Skip to content

Instantly share code, notes, and snippets.

@jonashackt
Created July 13, 2015 09:37
Show Gist options
  • Save jonashackt/a5605ce850dc3094432b to your computer and use it in GitHub Desktop.
Save jonashackt/a5605ce850dc3094432b to your computer and use it in GitHub Desktop.
Decode and write Base64-encoded ISO_8859_1 String to Pdf-File
private static void decodeAndWriteBase64Pdf() throws Exception {
System.out.print("Enter base64EncodedPdfAsIsoString (e.g. from SOAP-Call):");
Scanner s = new Scanner(System.in);
String base64EncodedPdfAsIsoString = s.nextLine();
s.close();
byte[] decodedPdf = Base64.getDecoder().decode(base64EncodedPdfAsIsoString);
writeFileInClasspath(decodedPdf);
}
private static void writeFileInClasspath(byte[] base64EncodedPdfAsIsoString) throws Exception {
try ( OutputStream out = Files.newOutputStream( Paths.get( "foo2.pdf" ))) {
out.write(base64EncodedPdfAsIsoString);
}
catch ( IOException exception) {
throw new Exception("Problem beim Schreiben der Datei: " + exception.getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment