public InputStream put(final URLConnection connection,final boolean flushCacheOnClose){
  final String key=getKey(connection);
  if (key == null)   return null;
  if (!isCacheable((HttpURLConnection)connection))   try {
    cache.remove(key);
    return null;
  }
 catch (  IOException e) {
    return null;
  }
  String etag=connection.getHeaderField(HEADER_ETAG);
  if (etag == null || etag.length() == 0)   return null;
  Editor editor;
  try {
    editor=cache.edit(key);
  }
 catch (  IOException e) {
    return null;
  }
  if (editor == null)   return null;
  try {
    editor.set(ETAG,etag);
  }
 catch (  IOException e) {
    try {
      editor.abort();
    }
 catch (    IOException ignored) {
    }
    return null;
  }
  InputStream input;
  try {
    input=connection.getInputStream();
    if (!(input instanceof InflaterInputStream) && ENCODING_GZIP.equals(connection.getHeaderField(HEADER_CONTENT_ENCODING)))     input=new GZIPInputStream(input);
  }
 catch (  IOException e) {
    return null;
  }
  OutputStream output;
  try {
    output=editor.newOutputStream(BODY);
  }
 catch (  IOException e) {
    return null;
  }
  if (output != null)   return new CacheStream(input,output,editor,this,flushCacheOnClose);
 else   return null;
}

public InputStream put ( final URLConnection connection , final boolean flushCacheOnClose ) { final String key = getKey ( connection ) ; if ( key == null ) return null ; if ( ! isCacheable ( ( HttpURLConnection ) connection ) ) try { cache . remove ( key ) ; return null ; } catch ( IOException e ) { return null ; } String etag = connection . getHeaderField ( HEADER_ETAG ) ; if ( etag == null || etag . length ( ) == 0 ) return null ; Editor editor ; try { editor = cache . edit ( key ) ; } catch ( IOException e ) { return null ; } if ( editor == null ) return null ; try { editor . set ( ETAG , etag ) ; } catch ( IOException e ) { try { editor . abort ( ) ; } catch ( IOException ignored ) { } return null ; } InputStream input ; try { input = connection . getInputStream ( ) ; if ( ! ( input instanceof InflaterInputStream ) && ENCODING_GZIP . equals ( connection . getHeaderField ( HEADER_CONTENT_ENCODING ) ) ) input = new GZIPInputStream ( input ) ; } catch ( IOException e ) { return null ; } OutputStream output ; try { output = editor . newOutputStream ( BODY ) ; } catch ( IOException e ) { return null ; } if ( output != null ) return new CacheStream ( input , output , editor , this , flushCacheOnClose ) ; else return null ; }
create stream that will be cached after it is read
