Component addComponent ( Consumer < IOException > onError ) { Component component ; try { long readable = readableBytes ( data ) ; long offset = position . getAndUpdate ( p -> readable ) ; int length = new Long ( readable - offset ) . intValue ( ) ; component = new Component ( length , offset ) ; components . add ( component ) ; } catch ( IOException e ) { onError . accept ( e ) ; return null ; } if ( ! data . isInMemory ( ) ) { fileAccess . getAndUpdate ( channel -> { if ( channel == null ) { try { return new RandomAccessFile ( data . getFile ( ) , "r" ) ; } catch ( IOException e ) { onError . accept ( e ) ; } } return channel ; } ) ; } return component ; }
Adds a reference to a section of the http data . Should only be called after data has been added to the underlying http data .