Source:
private void writeMetadata( final Transfer target, final ObjectMapper mapper, final Map<String, List<String>> requestHeaders ) { Transfer metaTxfr = target.getSiblingMeta( HttpExchangeMetadata.FILE_EXTENSION ); if ( metaTxfr == null ) { if ( target.isDirectory() ) { logger.debug( "DIRECTORY. Using HTTP exchange metadata file INSIDE directory called: {}", HttpExchangeMetadata.FILE_EXTENSION ); metaTxfr = target.getChild( HttpExchangeMetadata.FILE_EXTENSION ); } else { logger.debug( "SKIP: Cannot retrieve HTTP exchange metadata Transfer instance for: {}", target ); return; } } final HttpExchangeMetadata metadata = new HttpExchangeMetadataFromRequestHeader( requestHeaders ); OutputStream out = null; try { final Transfer finalMeta = metaTxfr; out = metaTxfr.openOutputStream( TransferOperation.GENERATE, false ); logger.debug( "Writing HTTP exchange metadata:\n\n{}\n\n", new Object() { @Override public String toString() { try { return mapper.writeValueAsString( metadata ); } catch ( final JsonProcessingException e ) { logger.warn( String.format("Failed to write HTTP exchange metadata: %s. Reason: %s", finalMeta, e.getMessage()), e ); } return "ERROR RENDERING METADATA"; } } ); out.write( mapper.writeValueAsBytes( metadata ) ); } catch ( final IOException e ) { if ( logger.isDebugEnabled() ) { logger.debug( String.format( "Failed to write metadata for HTTP exchange to: %s. Reason: %s", metaTxfr, e.getMessage() ), e ); } else { logger.warn( "Failed to write metadata for HTTP exchange to: {}. Reason: {}", metaTxfr, e.getMessage() ); } } finally { IOUtils.closeQuietly( out ); } }

Target:
private void writeMetadata( final Transfer target, final ObjectMapper mapper, final Map<String, List<String>> requestHeaders ) { Transfer metaTxfr = target.getSiblingMeta( HttpExchangeMetadata.FILE_EXTENSION ); if ( metaTxfr == null ) { if ( target.isDirectory() ) { logger.trace( "DIRECTORY. Using HTTP exchange metadata file INSIDE directory called: {}", HttpExchangeMetadata.FILE_EXTENSION ); metaTxfr = target.getChild( HttpExchangeMetadata.FILE_EXTENSION ); } else { logger.trace( "SKIP: Cannot retrieve HTTP exchange metadata Transfer instance for: {}", target ); return; } } final HttpExchangeMetadata metadata = new HttpExchangeMetadataFromRequestHeader( requestHeaders ); OutputStream out = null; try { final Transfer finalMeta = metaTxfr; out = metaTxfr.openOutputStream( TransferOperation.GENERATE, false ); logger.trace( "Writing HTTP exchange metadata:\n\n{}\n\n", new Object() { @Override public String toString() { try { return mapper.writeValueAsString( metadata ); } catch ( final JsonProcessingException e ) { logger.warn( String.format("Failed to write HTTP exchange metadata: %s. Reason: %s", finalMeta, e.getMessage()), e ); } return "ERROR RENDERING METADATA"; } } ); out.write( mapper.writeValueAsBytes( metadata ) ); } catch ( final IOException e ) { if ( logger.isTraceEnabled() ) { logger.trace( String.format( "Failed to write metadata for HTTP exchange to: %s. Reason: %s", metaTxfr, e.getMessage() ), e ); } else { logger.warn( "Failed to write metadata for HTTP exchange to: {}. Reason: {}", metaTxfr, e.getMessage() ); } } finally { IOUtils.closeQuietly( out ); } }