public class Base64OutputStreamWriter
extends java.io.OutputStream
Provides a mechanism to accept and Base64 encode bytes into chars which will be flushed to the provided writer as the internal buffer fills.
Modifier and Type | Field and Description |
---|---|
private byte[] |
buf
The buffer where data is stored.
|
private static char[] |
CA |
private char[] |
chars
The Base64 encoded bytes as chars; essentially the output
buffer
|
private int |
count
The number of valid bytes in the buffer.
|
private int |
encCount
The current position within
chars |
private int |
totalCharsWritten
Tracks the total number of characters written.
|
private java.io.Writer |
writer
The writer we'll flush the bytes to instead of growing
the array.
|
Constructor and Description |
---|
Base64OutputStreamWriter(int size,
java.io.Writer writer)
Creates a new byte array output stream, with a buffer capacity of
the specified size, in bytes.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closing Base64OutputStreamWriter does nothing.
|
private void |
drainCharBuffer()
Write the contents of
chars to the
wrapped Writer and reset encCount
to zero. |
private void |
encodePendingBytes(boolean pad)
Base64 encode any bytes found in
buf and
store the result as characters in chars . |
void |
finish()
Encodes the remaining bytes and flushes the
char[]
to the wrapped Writer . |
int |
getTotalCharsWritten() |
void |
write(byte[] b)
Calls through to
write(byte[], int, int) / |
void |
write(byte[] b,
int off,
int len)
Writes
len bytes from the specified byte array
starting at offset off to this byte array output stream. |
void |
write(int b)
Writes the specified byte to this byte array output stream.
|
private byte[] buf
private char[] chars
The Base64 encoded bytes as chars; essentially the output buffer
private int count
private int encCount
The current position within chars
private int totalCharsWritten
Tracks the total number of characters written.
private java.io.Writer writer
private static final char[] CA
public Base64OutputStreamWriter(int size, java.io.Writer writer)
size
- the initial size.writer
- the writer we'll flush to once
we reach our capacityjava.lang.IllegalArgumentException
- if size is negative.public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
b
- the byte to be written.java.io.IOException
public void write(byte[] b, int off, int len) throws java.io.IOException
len
bytes from the specified byte array
starting at offset off
to this byte array output stream.write
in class java.io.OutputStream
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.java.io.IOException
public void write(byte[] b) throws java.io.IOException
Calls through to write(byte[], int, int)
/
write
in class java.io.OutputStream
b
- the bytes to writejava.io.IOException
- if an error occurspublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
public void finish() throws java.io.IOException
Encodes the remaining bytes and flushes the char[]
to the wrapped Writer
.
java.io.IOException
- if an error occurs writing the remaining bytespublic int getTotalCharsWritten()
private void encodePendingBytes(boolean pad) throws java.io.IOException
Base64 encode any bytes found in buf
and
store the result as characters in chars
. This method
will automatically write the contents of chars
when
necessary.
pad
- flag to signal we're finalizing the encoding processes.java.io.IOException
- if an error occursprivate void drainCharBuffer() throws java.io.IOException
Write the contents of chars
to the
wrapped Writer
and reset encCount
to zero.
java.io.IOException
- if an error occursCopyright © 2002-2013 Oracle America, Inc. All Rights Reserved.