@ -105,6 +105,7 @@ public final class httpc {
}
}
private static final httpcPool theHttpcPool ;
private static final httpcPool theHttpcPool ;
boolean removedFromPool = false ;
static {
static {
// implementation of session thread pool
// implementation of session thread pool
GenericObjectPool . Config config = new GenericObjectPool . Config ( ) ;
GenericObjectPool . Config config = new GenericObjectPool . Config ( ) ;
@ -129,17 +130,18 @@ public final class httpc {
public static httpc getInstance ( String server , int port , int timeout , boolean ssl ,
public static httpc getInstance ( String server , int port , int timeout , boolean ssl ,
String remoteProxyHost , int remoteProxyPort ) throws IOException {
String remoteProxyHost , int remoteProxyPort ) throws IOException {
httpc newHttpc ;
try {
try {
// fetching a new httpc from the object pool
// fetching a new httpc from the object pool
httpc newHttpc = ( httpc ) httpc . theHttpcPool . borrowObject ( ) ;
newHttpc = ( httpc ) httpc . theHttpcPool . borrowObject ( ) ;
// initialize it
newHttpc . init ( server , port , timeout , ssl , remoteProxyHost , remoteProxyPort ) ;
return newHttpc ;
} catch ( Exception e ) {
} catch ( Exception e ) {
throw new IOException ( "Unable to initialize a new httpc. " + e . getMessage ( ) ) ;
throw new IOException ( "Unable to initialize a new httpc. " + e . getMessage ( ) ) ;
}
}
// initialize it
newHttpc . init ( server , port , timeout , ssl , remoteProxyHost , remoteProxyPort ) ;
return newHttpc ;
}
}
public static httpc getInstance ( String server , int port , int timeout , boolean ssl ) throws IOException {
public static httpc getInstance ( String server , int port , int timeout , boolean ssl ) throws IOException {
@ -167,7 +169,7 @@ public final class httpc {
}
}
protected void finalize ( ) throws Throwable {
protected void finalize ( ) throws Throwable {
System . err . println ( "Httpc object was not returned to object pool." ) ;
if ( ! this . removedFromPool ) System . err . println ( "Httpc object was not returned to object pool." ) ;
this . reset ( ) ;
this . reset ( ) ;
httpc . theHttpcPool . invalidateObject ( this ) ;
httpc . theHttpcPool . invalidateObject ( this ) ;
}
}
@ -417,7 +419,7 @@ public final class httpc {
public byte [ ] writeContent ( OutputStream procOS ) throws IOException {
public byte [ ] writeContent ( OutputStream procOS ) throws IOException {
serverByteBuffer sbb = new serverByteBuffer ( ) ;
serverByteBuffer sbb = new serverByteBuffer ( ) ;
writeContentX ( procOS , sbb );
writeContentX ( procOS , sbb , httpc . this . clientInput );
return sbb . getBytes ( ) ;
return sbb . getBytes ( ) ;
}
}
@ -426,14 +428,14 @@ public final class httpc {
// a file or both.
// a file or both.
FileOutputStream bufferOS = null ;
FileOutputStream bufferOS = null ;
if ( file ! = null ) bufferOS = new FileOutputStream ( file ) ;
if ( file ! = null ) bufferOS = new FileOutputStream ( file ) ;
writeContentX ( procOS , bufferOS );
writeContentX ( procOS , bufferOS , httpc . this . clientInput );
if ( bufferOS ! = null ) {
if ( bufferOS ! = null ) {
bufferOS . close ( ) ;
bufferOS . close ( ) ;
if ( file . length ( ) = = 0 ) file . delete ( ) ;
if ( file . length ( ) = = 0 ) file . delete ( ) ;
}
}
}
}
public void writeContentX ( OutputStream procOS , OutputStream bufferOS ) throws IOException {
public void writeContentX ( OutputStream procOS , OutputStream bufferOS , InputStream clientInput ) throws IOException {
// we write length bytes, but if length == -1 (or < 0) then we
// we write length bytes, but if length == -1 (or < 0) then we
// write until the input stream closes
// write until the input stream closes
// procOS == null -> no write to procOS
// procOS == null -> no write to procOS
@ -473,7 +475,7 @@ public final class httpc {
}
}
baos . flush ( ) ;
baos . flush ( ) ;
// now uncompress
// now uncompress
InputStream dis = ( InputStream ) new GZIPInputStream ( new ByteArrayInputStream ( baos . toByteArray ( ) ) ) ;
InputStream dis = new GZIPInputStream ( new ByteArrayInputStream ( baos . toByteArray ( ) ) ) ;
try {
try {
while ( ( l = dis . read ( buffer ) ) > 0 ) {
while ( ( l = dis . read ( buffer ) ) > 0 ) {
if ( procOS ! = null ) procOS . write ( buffer , 0 , l ) ;
if ( procOS ! = null ) procOS . write ( buffer , 0 , l ) ;
@ -1180,6 +1182,7 @@ final class httpcFactory implements org.apache.commons.pool.PoolableObjectFactor
public void destroyObject ( Object obj ) {
public void destroyObject ( Object obj ) {
if ( obj instanceof httpc ) {
if ( obj instanceof httpc ) {
httpc theHttpc = ( httpc ) obj ;
httpc theHttpc = ( httpc ) obj ;
theHttpc . removedFromPool = true ;
}
}
}
}