public void decode ( InputStream is , OutputStream os ) throws IOException { int read , idx = 0 ; int prev = 0 , index ; while ( ( read = is . read ( ) ) >= 0 ) { index = convert . convert ( read ) ; if ( index >= 0 ) { switch ( ++ idx ) { // 1 based cases, slightly faster ++ case 1 : // index goes into first 6 bits of prev prev = index << 2 ; break ; case 2 : // write second 2 bits of into prev, write byte, last 4 bits go into prev os . write ( ( byte ) ( prev | ( index >> 4 ) ) ) ; prev = index << 4 ; break ; case 3 : // first 4 bits of index goes into prev, write byte, last 2 bits go into prev os . write ( ( byte ) ( prev | ( index >> 2 ) ) ) ; prev = index << 6 ; break ; default : // (3+) | prev and last six of index os . write ( ( byte ) ( prev | ( index & 0x3F ) ) ) ; idx = prev = 0 ; } } } ; os . flush ( ) ; }
Decode InputStream onto OutputStream