List of usage examples for org.apache.commons.codec.binary Base64OutputStream Base64OutputStream
public Base64OutputStream(OutputStream out, boolean doEncode, int lineLength, byte[] lineSeparator)
From source file:org.xwiki.store.serialization.xml.internal.XMLWriter.java
/** * Writes the <code>{@link Element}</code>, including its <code>{@link * Attribute}</code>s, using the/*from w ww . jav a 2 s . c om*/ * <code>{@link InputStream}</code> encoded in Base64 for its content. * * @param element <code>{@link Element}</code> to output. * @param is <code>{@link InputStream}</code> that will be fully read and encoded * in Base64 into the element content. * @throws IOException a problem occurs during reading or writing. */ public void writeBase64(final Element element, final InputStream is) throws IOException { this.writeOpen(element); super.writePrintln(); super.flush(); final Base64OutputStream base64 = new Base64OutputStream(new CloseShieldOutputStream(this.out), true, BASE64_WIDTH, NEWLINE); IOUtils.copy(is, base64); base64.close(); // The last char written was a newline, not a > so it will not indent unless it is done manually. super.setIndentLevel(this.parent.size() - 1); super.indent(); this.writeClose(element); }
From source file:org.yes.cart.shoppingcart.support.impl.AbstractCryptedTuplizerImpl.java
/** * Converts cart object into a String tuple. * * @param serializable cart//from w ww. j a v a 2 s . com * * @return string * * @throws CartTuplizationException when cannot convert to string tuple */ protected String toToken(final Serializable serializable) throws CartTuplizationException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); synchronized (desCipher) { Base64OutputStream base64EncoderStream = new Base64OutputStream(byteArrayOutputStream, true, Integer.MAX_VALUE, null); //will be split manually CipherOutputStream cipherOutputStream = new CipherOutputStream(base64EncoderStream, desCipher); ObjectOutputStream objectOutputStream = null; try { objectOutputStream = new ObjectOutputStream(cipherOutputStream); objectOutputStream.writeObject(serializable); objectOutputStream.flush(); objectOutputStream.close(); } catch (Throwable ioe) { LOG.error(MessageFormat.format("Unable to serialize object {0}", serializable), ioe); throw new CartTuplizationException(ioe); } finally { try { if (objectOutputStream != null) { objectOutputStream.close(); } cipherOutputStream.close(); base64EncoderStream.close(); byteArrayOutputStream.close(); } catch (IOException e) { LOG.error("Can not close stream", e); } } } return byteArrayOutputStream.toString(); }