Writes the byte to the output stream after converting to/from Base64 notation. When encoding, bytes are buffered three at a time before the output stream actually gets a write() call. When decoding, bytes are buffered four at a time. @param theByte the byte to write @since 1.3
(int theByte)
| 1910 | * @since 1.3 |
| 1911 | */ |
| 1912 | @Override |
| 1913 | public void write(int theByte) |
| 1914 | throws java.io.IOException { |
| 1915 | // Encoding suspended? |
| 1916 | if( suspendEncoding ) { |
| 1917 | this.out.write( theByte ); |
| 1918 | return; |
| 1919 | } // end if: supsended |
| 1920 | |
| 1921 | // Encode? |
| 1922 | if( encode ) { |
| 1923 | buffer[ position++ ] = (byte)theByte; |
| 1924 | if( position >= bufferLength ) { // Enough to encode. |
| 1925 | |
| 1926 | this.out.write( encode3to4( b4, buffer, bufferLength, options ) ); |
| 1927 | |
| 1928 | lineLength += 4; |
| 1929 | if( breakLines && lineLength >= MAX_LINE_LENGTH ) { |
| 1930 | this.out.write( NEW_LINE ); |
| 1931 | lineLength = 0; |
| 1932 | } // end if: end of line |
| 1933 | |
| 1934 | position = 0; |
| 1935 | } // end if: enough to output |
| 1936 | } // end if: encoding |
| 1937 | |
| 1938 | // Else, Decoding |
| 1939 | else { |
| 1940 | // Meaningful Base64 character? |
| 1941 | if( decodabet[ theByte & 0x7f ] > WHITE_SPACE_ENC ) { |
| 1942 | buffer[ position++ ] = (byte)theByte; |
| 1943 | if( position >= bufferLength ) { // Enough to output. |
| 1944 | |
| 1945 | int len = Base64.decode4to3( buffer, 0, b4, 0, options ); |
| 1946 | out.write( b4, 0, len ); |
| 1947 | position = 0; |
| 1948 | } // end if: enough to output |
| 1949 | } // end if: meaningful base64 character |
| 1950 | else if( decodabet[ theByte & 0x7f ] != WHITE_SPACE_ENC ) { |
| 1951 | throw new java.io.IOException( "Invalid character in Base64 data." ); |
| 1952 | } // end else: not white space either |
| 1953 | } // end else: decoding |
| 1954 | } // end write |
| 1955 | |
| 1956 | |
| 1957 |
no test coverage detected