Klasse Base64OutputStream

java.lang.Object
java.io.OutputStream
de.uplanet.util.base64.Base64OutputStream
Alle implementierten Schnittstellen:
Closeable, Flushable, AutoCloseable

@Scriptable public final class Base64OutputStream extends OutputStream
Base64 encoding as described in RFC 2045 section 6.8.
0 A17 R34 i51 z
1 B18 S35 j52 0
2 C19 T36 k53 1
3 D20 U37 l54 2
4 E21 V38 m55 3
5 F22 W39 n56 4
6 G23 X40 o57 5
7 H24 Y41 p58 6
8 I25 Z42 q59 7
9 J26 a43 r60 8
10 K27 b44 s61 9
11 L28 c45 t62 +
12 M29 d46 u63 /
13 N30 e47 v
14 O31 f48 w(pad) =
15 P32 g49 x
16 Q33 h50 y


This stream-based encoding will outperform Base64Encoder when writing data sizes beyond about 400 bytes to a StringWriter provided that the output buffer is properly preallocated using the outputSizeFromInputSize(int) method. In these cases use the following pattern:

    byte[] l_data;

    // ...
    
    StringWriter       l_sw  = new StringWriter(Base64OutputStream.outputSizeFromInputSize(l_data.length));
    Base64OutputStream l_out = new Base64OutputStream(l_sw);

    l_out.write(l_data);
    l_out.close();

    String l_strEncoded = l_sw.toString();
Siehe auch:
  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
    Constructor for Base64OutputStream.
    Constructor for Base64OutputStream.
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    void
    Close the stream, finish()ing encoding and flush()ing it first.
    void
    Finishes writing base64-encoded data to the output stream without closing the underlying stream.
    void
    Flush the stream.
    static int
    Calculates the size of the output for the given input size.
    void
    write(byte[] p_buf)
    Writes an array of bytes to the base64-encoded output stream.
    void
    write(byte[] p_buf, int p_iOffs, int p_iLen)
    Writes an array of bytes to the base64-encoded output stream.
    void
    write(int p_byte)
    Writes a single byte to the base64-encoded output stream.

    Von Klasse geerbte Methoden java.io.OutputStream

    nullOutputStream

    Von Klasse geerbte Methoden java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Konstruktordetails

    • Base64OutputStream

      public Base64OutputStream(Writer p_out)
      Constructor for Base64OutputStream. Creates a new base64 output stream to write data to the specified underlying output stream with a default 512-byte buffer size.
      Parameter:
      p_out - The underlying stream.
    • Base64OutputStream

      public Base64OutputStream(XMLStreamWriter p_xmlStreamWriter)
      Constructor for Base64OutputStream. Creates a new base64 output stream to write data to the specified XMLStreamWriter with a default 512-byte buffer size.
      Parameter:
      p_xmlStreamWriter - The p_xmlStreamWriter to write to.
  • Methodendetails

    • outputSizeFromInputSize

      public static int outputSizeFromInputSize(int p_iSize)
      Calculates the size of the output for the given input size. Note: values obtained for chunks of data are not additive.
      Parameter:
      p_iSize - The input size in bytes.
      Gibt zurück:
      The output size in characters.
    • write

      public void write(int p_byte) throws IOException
      Writes a single byte to the base64-encoded output stream.
      Angegeben von:
      write in Klasse OutputStream
      Parameter:
      p_byte - The byte to be written.
      Löst aus:
      IOException - If an I/O error occurs.
    • write

      public void write(byte[] p_buf) throws IOException
      Writes an array of bytes to the base64-encoded output stream.
      Setzt außer Kraft:
      write in Klasse OutputStream
      Parameter:
      p_buf - The data to be written.
      Löst aus:
      IOException - If an I/O error occurs.
    • write

      public void write(byte[] p_buf, int p_iOffs, int p_iLen) throws IOException
      Writes an array of bytes to the base64-encoded output stream.
      Setzt außer Kraft:
      write in Klasse OutputStream
      Parameter:
      p_buf - The data to be written.
      p_iOffs - The start offset of the data.
      p_iLen - The length of the data.
      Löst aus:
      IOException - If an I/O error occurs.
    • finish

      public void finish() throws IOException
      Finishes writing base64-encoded data to the output stream without closing the underlying stream.
      Löst aus:
      IOException - If an I/O error occurs.
    • flush

      public void flush() throws IOException
      Flush the stream. Note: at most two bytes may not be flushed unless finish() is applied.
      Angegeben von:
      flush in Schnittstelle Flushable
      Setzt außer Kraft:
      flush in Klasse OutputStream
      Löst aus:
      IOException - If an I/O error occurs.
    • close

      public void close() throws IOException
      Close the stream, finish()ing encoding and flush()ing it first.
      Angegeben von:
      close in Schnittstelle AutoCloseable
      Angegeben von:
      close in Schnittstelle Closeable
      Setzt außer Kraft:
      close in Klasse OutputStream
      Löst aus:
      IOException - If an I/O error occurs.