@ Override public int read ( byte [ ] buffer , int offset , int length ) throws IOException { int b = - 1 ; if ( _isPartDone ) return - 1 ; int i = 0 ; // Need the last peek or would miss the initial '\n' while ( _peekOffset + 1 < _peekLength && length > 0 ) { buffer [ offset + i ++ ] = _peek [ _peekOffset ++ ] ; length -- ; } while ( i < length && ( b = read ( ) ) >= 0 ) { boolean hasCr = false ; if ( b == ' ' ) { hasCr = true ; b = read ( ) ; // XXX: Macintosh? if ( b != ' ' ) { buffer [ offset + i ++ ] = ( byte ) ' ' ; _peek [ 0 ] = ( byte ) b ; _peekOffset = 0 ; _peekLength = 1 ; continue ; } } else if ( b != ' ' ) { buffer [ offset + i ++ ] = ( byte ) b ; continue ; } int j ; for ( j = 0 ; j < _boundaryLength && ( b = read ( ) ) >= 0 && _boundaryBuffer [ j ] == b ; j ++ ) { } if ( j == _boundaryLength ) { _isPartDone = true ; if ( ( b = read ( ) ) == ' ' ) { if ( ( b = read ( ) ) == ' ' ) { _isDone = true ; _isComplete = true ; } } for ( ; b > 0 && b != ' ' && b != ' ' ; b = read ( ) ) { } if ( b == ' ' && ( b = read ( ) ) != ' ' ) { _peek [ 0 ] = ( byte ) b ; _peekOffset = 0 ; _peekLength = 1 ; } return i > 0 ? i : - 1 ; } _peekLength = 0 ; if ( hasCr && i + 1 < length ) { buffer [ offset + i ++ ] = ( byte ) ' ' ; buffer [ offset + i ++ ] = ( byte ) ' ' ; } else if ( hasCr ) { buffer [ offset + i ++ ] = ( byte ) ' ' ; _peek [ _peekLength ++ ] = ( byte ) ' ' ; } else { buffer [ offset + i ++ ] = ( byte ) ' ' ; } int k = 0 ; while ( k < j && i + 1 < length ) buffer [ offset + i ++ ] = _boundaryBuffer [ k ++ ] ; while ( k < j ) _peek [ _peekLength ++ ] = _boundaryBuffer [ k ++ ] ; _peek [ _peekLength ++ ] = ( byte ) b ; _peekOffset = 0 ; } if ( i <= 0 ) { _isPartDone = true ; if ( b < 0 ) _isDone = true ; return - 1 ; } else { return i ; } }
Reads from the multipart mime buffer .