/** * Reads <tt>infile</tt> and decodes it to <tt>outfile</tt>. * * @param infile Input file * @param outfile Output file * * @throws java.io.IOException if there is an error * @since 2.2 */ public static void decodeFileToFile(String infile, String outfile) throws IOException { byte[] decoded = Base64.decodeFromFile(infile); java.io.OutputStream out = null; try { out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile)); out.write(decoded); } catch (IOException ex) { throw ex; } finally { closeQuietly(out); } }
/** * Reads <tt>infile</tt> and encodes it to <tt>outfile</tt>. * * @param infile Input file * @param outfile Output file * @throws java.io.IOException if there is an error * @since 2.2 */ public static void encodeFileToFile(String infile, String outfile) throws IOException { String encoded = Base64.encodeFromFile(infile); java.io.OutputStream out = null; try { out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile)); out.write(encoded.getBytes("US-ASCII")); // Strict, 7-bit output. } catch (IOException ex) { throw ex; } finally { closeQuietly(out); } }
closeQuietly(baos); closeQuietly(gzis); closeQuietly(bais);
throw ex; } finally { closeQuietly(bais); closeQuietly(ois);
closeQuietly(oos); closeQuietly(gzos); closeQuietly(b64os); closeQuietly(baos);
throw ex; } finally { closeQuietly(bis);
/** * Convenience method for decoding data to a file. * * <p>As of v 2.3, if there is a error, * the method will throw an java.io.IOException. <b>This is new to v2.3!</b> * In earlier versions, it just returned false, but * in retrospect that's a pretty poor way to handle it.</p> * * @param dataToDecode Base64-encoded data as a string * @param filename Filename for saving decoded data * @throws java.io.IOException if there is an error * @since 2.1 */ public static void decodeToFile(String dataToDecode, String filename) throws IOException { Base64.OutputStream bos = null; try { bos = new Base64.OutputStream(new java.io.FileOutputStream(filename), Base64.DECODE); bos.write(dataToDecode.getBytes(PREFERRED_ENCODING)); } catch (IOException ex) { throw ex; } finally { closeQuietly(bos); } }
/** * Convenience method for encoding data to a file. * * <p>As of v 2.3, if there is a error, * the method will throw an java.io.IOException. <b>This is new to v2.3!</b> * In earlier versions, it just returned false, but * in retrospect that's a pretty poor way to handle it.</p> * * @param dataToEncode byte array of data to encode in base64 form * @param filename Filename for saving encoded data * @throws IOException if there is an error * @throws NullPointerException if dataToEncode is null * @since 2.1 */ public static void encodeToFile(byte[] dataToEncode, String filename) throws IOException { Objects.requireNonNull(dataToEncode, "Data to encode was null."); Base64.OutputStream bos = null; try { bos = new Base64.OutputStream(new java.io.FileOutputStream(filename), Base64.ENCODE); bos.write(dataToEncode); } catch (IOException ex) { throw ex; } finally { closeQuietly(bos); } }
throw ex; } finally { closeQuietly(bis);
throw ex; } finally { closeQuietly(gzos); closeQuietly(b64os); closeQuietly(baos);