/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A stream that has the property of being able to be kept alive for
* multiple downloads from the same server.
*
* @author Stephen R. Pietrowicz (NCSA)
* @author Dave Brown
*/
public
// instance variables
boolean hurried;
// has this KeepAliveStream been put on the queue for asynchronous cleanup.
protected boolean queuedForCleanup = false;
/**
* Constructor
*/
}
/**
* Attempt to cache this connection
*/
// If the inputstream is closed already, just return.
if (closed) {
return;
}
// If this stream has already been queued for cleanup.
if (queuedForCleanup) {
return;
}
// Skip past the data that's left in the Inputstream because
// some sort of error may have occurred.
// Do this ONLY if the skip won't block. The stream may have
// been closed at the beginning of a big file and we don't want
// to hang around for nothing. So if we can't skip without blocking
// we just close the socket and, therefore, terminate the keepAlive
// NOTE: Don't close super class
try {
long n = 0;
while (n < nskip) {
}
//put this KeepAliveStream on the queue so that the data remaining
//on the socket can be cleanup asyncronously.
} else {
hc.closeServer();
}
}
}
} finally {
pi.finishTracking();
if (!queuedForCleanup) {
// nulling out the underlying inputstream as well as
// httpClient to let gc collect the memories faster
closed = true;
}
}
}
public boolean markSupported() {
return false;
}
throw new IOException("mark/reset not supported");
}
public synchronized boolean hurry() {
try {
/* CASE 0: we're actually already done */
return false;
/* CASE I: can't meet the demand */
return false;
} else {
/* CASE II: fill our internal buffer
* Remind: possibly check memory here
*/
hurried = true;
return true;
}
} catch (IOException e) {
// e.printStackTrace();
return false;
}
}
synchronized(queue) {
if(!kace.getQueuedForCleanup()) {
return;
}
}
if (!startCleanupThread) {
if (!cleanerThread.isAlive()) {
startCleanupThread = true;
}
}
if (startCleanupThread) {
// We want to create the Keep-Alive-SocketCleaner in the
// system threadgroup
}
cleanerThread.setDaemon(true);
// Set the context class loader to null in order to avoid
// keeping a strong reference to an application classloader.
return null;
}
});
}
} // queue
}
protected long remainingToRead() {
}
protected void setClosed() {
closed = true;
}
}
class KeepAliveCleanerEntry
{
}
return kas;
}
return hc;
}
protected void setQueuedForCleanup() {
kas.queuedForCleanup = true;
}
protected boolean getQueuedForCleanup() {
return kas.queuedForCleanup;
}
}