Author: kono
Date: 2011-12-14 13:15:07 -0800 (Wed, 14 Dec 2011)
New Revision: 27793
Modified:
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/util/StreamUtil.java
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTask.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/CyActivator.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CopyInputStream.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyNetworkReaderManagerImpl.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyPropertyReaderManagerImpl.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CySessionReaderManagerImpl.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyTableReaderManagerImpl.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/GenericReaderManager.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/MarkSupportedInputStream.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/VizmapReaderManagerImpl.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/AbstractSessionReader.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/ReadUtils.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/StreamUtilImpl.java
Log:
Made reader managers uses streamUtil to pick Proxy (if available). Also,
MarkSupportedInputStream is replaced by ByfferedInputStream for network loading.
Modified:
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java
===================================================================
---
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -91,7 +91,6 @@
return false;
try {
-
final URLConnection connection =
streamUtil.getURLConnection(uri.toURL());
final String contentType = connection.getContentType();
Modified:
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/util/StreamUtil.java
===================================================================
--- core3/api/trunk/io-api/src/main/java/org/cytoscape/io/util/StreamUtil.java
2011-12-14 21:06:25 UTC (rev 27792)
+++ core3/api/trunk/io-api/src/main/java/org/cytoscape/io/util/StreamUtil.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -12,32 +12,25 @@
*/
public interface StreamUtil {
- // TODO what's the difference between these two methods?
/**
* Gets the input stream from given {@link java.net.URL}.
+ * Proxy will be used if available.
+ *
* @param source The URL from which to generate the InputStream.
* @return An input stream from the specified URL.
* @throws IOException
*/
- InputStream getInputStream(URL source) throws IOException;
+ InputStream getInputStream(final URL source) throws IOException;
- /**
- * Obtain an InputStream for a given URL. Ensure proxy servers and an
input
- * stream to the real URL source is created--not a locally cached and
out of
- * date source. Proxy servers and other characteristics can cause pages
to
- * be cached.
- * @param source The URL from which to generate the InputStream.
- * @return An input stream from the specified URL.
- * @throws IOException
- */
- InputStream getBasicInputStream(URL source) throws IOException;
/**
* Obtain a {@link java.net.URLConnection} for a given {@link
java.net.URL}.
+ * Proxy will be used if available.
+ *
* @param source The URL from which to generate the URLConnection.
* @return An URLConnection from the specified URL.
* @throws IOException
*/
- URLConnection getURLConnection(URL source) throws IOException;
+ URLConnection getURLConnection(final URL source) throws IOException;
}
Modified:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTask.java
===================================================================
---
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTask.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTask.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -89,7 +89,7 @@
if (cancelled)
return;
- taskMonitor.setStatusMessage("Finding network reader...");
+ taskMonitor.setStatusMessage("Finding compatible network reader
for this file...");
reader = mgr.getReader(url.toURI(),url.toString());
if (cancelled)
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/CyActivator.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/CyActivator.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/CyActivator.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -134,6 +134,7 @@
EquationCompiler equationCompilerServiceRef =
getService(bc,EquationCompiler.class);
CyRootNetworkManager cyRootNetworkFactoryServiceRef =
getService(bc,CyRootNetworkManager.class);
+ // TODO: set proxy
StreamUtilImpl streamUtil = new StreamUtilImpl();
BasicCyFileFilter expressionFilter = new BasicCyFileFilter(new
String[]{"pvals"}, new String[]{"text/plain"},"Cytoscape Expression Matrix
(.pvals) File", DataCategory.TABLE, streamUtil);
@@ -159,11 +160,11 @@
VizmapXMLFileFilter vizmapXMLFilter = new
VizmapXMLFileFilter(new String[]{"xml"}, new String[]{}, "Vizmap XML
files",DataCategory.VIZMAP, streamUtil);
VizmapPropertiesFileFilter vizmapPropertiesFilter = new
VizmapPropertiesFileFilter(new String[]{"props","properties"}, new String[]{},
"Vizmap Java Properties files",DataCategory.VIZMAP, streamUtil);
- CyNetworkReaderManagerImpl cyNetworkReaderManager = new
CyNetworkReaderManagerImpl();
- CyTableReaderManagerImpl cyDataTableReaderManager = new
CyTableReaderManagerImpl();
- CySessionReaderManagerImpl cySessionReaderManager = new
CySessionReaderManagerImpl();
- VizmapReaderManagerImpl vizmapReaderManager = new
VizmapReaderManagerImpl();
- CyPropertyReaderManagerImpl cyPropertyReaderManager = new
CyPropertyReaderManagerImpl();
+ CyNetworkReaderManagerImpl cyNetworkReaderManager = new
CyNetworkReaderManagerImpl(streamUtil);
+ CyTableReaderManagerImpl cyDataTableReaderManager = new
CyTableReaderManagerImpl(streamUtil);
+ CySessionReaderManagerImpl cySessionReaderManager = new
CySessionReaderManagerImpl(streamUtil);
+ VizmapReaderManagerImpl vizmapReaderManager = new
VizmapReaderManagerImpl(streamUtil);
+ CyPropertyReaderManagerImpl cyPropertyReaderManager = new
CyPropertyReaderManagerImpl(streamUtil);
PresentationWriterManagerImpl viewWriterManager = new
PresentationWriterManagerImpl();
CyNetworkViewWriterManagerImpl networkViewWriterManager = new
CyNetworkViewWriterManagerImpl();
SessionWriterManagerImpl sessionWriterManager = new
SessionWriterManagerImpl();
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CopyInputStream.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CopyInputStream.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CopyInputStream.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -24,8 +24,13 @@
copy.write(data, 0, chunk);
}
- if ( is.markSupported() )
- is.reset();
+ if (is.markSupported()) {
+ try {
+ is.reset();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
return new ByteArrayInputStream( copy.toByteArray() );
}
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyNetworkReaderManagerImpl.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyNetworkReaderManagerImpl.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyNetworkReaderManagerImpl.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -1,14 +1,15 @@
package org.cytoscape.io.internal.read;
+import org.cytoscape.io.DataCategory;
import org.cytoscape.io.read.CyNetworkReader;
import org.cytoscape.io.read.CyNetworkReaderManager;
import org.cytoscape.io.read.InputStreamTaskFactory;
-import org.cytoscape.io.DataCategory;
+import org.cytoscape.io.util.StreamUtil;
public class CyNetworkReaderManagerImpl extends
GenericReaderManager<InputStreamTaskFactory, CyNetworkReader> implements
CyNetworkReaderManager {
- public CyNetworkReaderManagerImpl() {
- super(DataCategory.NETWORK);
+ public CyNetworkReaderManagerImpl(final StreamUtil streamUtil) {
+ super(DataCategory.NETWORK, streamUtil);
}
}
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyPropertyReaderManagerImpl.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyPropertyReaderManagerImpl.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyPropertyReaderManagerImpl.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -1,16 +1,15 @@
package org.cytoscape.io.internal.read;
-
+import org.cytoscape.io.DataCategory;
import org.cytoscape.io.read.CyPropertyReader;
import org.cytoscape.io.read.CyPropertyReaderManager;
import org.cytoscape.io.read.InputStreamTaskFactory;
-import org.cytoscape.io.DataCategory;
+import org.cytoscape.io.util.StreamUtil;
+public class CyPropertyReaderManagerImpl extends
GenericReaderManager<InputStreamTaskFactory, CyPropertyReader>
+ implements CyPropertyReaderManager {
-public class CyPropertyReaderManagerImpl extends
GenericReaderManager<InputStreamTaskFactory, CyPropertyReader>
- implements CyPropertyReaderManager {
-
- public CyPropertyReaderManagerImpl() {
- super(DataCategory.PROPERTIES);
+ public CyPropertyReaderManagerImpl(final StreamUtil streamUtil) {
+ super(DataCategory.PROPERTIES, streamUtil);
}
}
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CySessionReaderManagerImpl.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CySessionReaderManagerImpl.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CySessionReaderManagerImpl.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -1,15 +1,15 @@
package org.cytoscape.io.internal.read;
+import org.cytoscape.io.DataCategory;
import org.cytoscape.io.read.CySessionReader;
import org.cytoscape.io.read.CySessionReaderManager;
import org.cytoscape.io.read.InputStreamTaskFactory;
-import org.cytoscape.io.DataCategory;
+import org.cytoscape.io.util.StreamUtil;
-public class CySessionReaderManagerImpl extends
- GenericReaderManager<InputStreamTaskFactory, CySessionReader>
implements
+public class CySessionReaderManagerImpl extends
GenericReaderManager<InputStreamTaskFactory, CySessionReader> implements
CySessionReaderManager {
- public CySessionReaderManagerImpl() {
- super(DataCategory.SESSION);
+ public CySessionReaderManagerImpl(final StreamUtil streamUtil) {
+ super(DataCategory.SESSION, streamUtil);
}
}
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyTableReaderManagerImpl.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyTableReaderManagerImpl.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/CyTableReaderManagerImpl.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -1,16 +1,15 @@
package org.cytoscape.io.internal.read;
-
+import org.cytoscape.io.DataCategory;
import org.cytoscape.io.read.CyTableReader;
import org.cytoscape.io.read.CyTableReaderManager;
import org.cytoscape.io.read.InputStreamTaskFactory;
-import org.cytoscape.io.DataCategory;
+import org.cytoscape.io.util.StreamUtil;
+public class CyTableReaderManagerImpl extends
GenericReaderManager<InputStreamTaskFactory, CyTableReader> implements
+ CyTableReaderManager {
-public class CyTableReaderManagerImpl extends
GenericReaderManager<InputStreamTaskFactory, CyTableReader>
- implements CyTableReaderManager {
-
- public CyTableReaderManagerImpl() {
- super(DataCategory.TABLE);
+ public CyTableReaderManagerImpl(final StreamUtil streamUtil) {
+ super(DataCategory.TABLE, streamUtil);
}
}
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/GenericReaderManager.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/GenericReaderManager.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/GenericReaderManager.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -1,31 +1,36 @@
package org.cytoscape.io.internal.read;
+import java.io.BufferedInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.HashSet;
-import java.io.IOException;
import org.cytoscape.io.CyFileFilter;
import org.cytoscape.io.DataCategory;
import org.cytoscape.io.read.InputStreamTaskFactory;
+import org.cytoscape.io.util.StreamUtil;
import org.cytoscape.work.Task;
-
+import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.slf4j.Logger;
public class GenericReaderManager<T extends InputStreamTaskFactory, R extends
Task> {
private static final Logger logger = LoggerFactory.getLogger(
GenericReaderManager.class );
- protected final DataCategory category;
+ protected final DataCategory category;
+ protected final StreamUtil streamUtil;
+
protected final Set<T> factories;
- public GenericReaderManager(DataCategory category) {
+ public GenericReaderManager(final DataCategory category, final
StreamUtil streamUtil) {
this.category = category;
+ this.streamUtil = streamUtil;
+
factories = new HashSet<T>();
}
@@ -64,19 +69,27 @@
*/
public R getReader(URI uri, String inputName) {
- logger.debug("Number of tunableHandlerFactories: " +
factories.size());
- for (T factory : factories) {
+ if(uri == null) {
+ logger.warn("URI is null");
+ return null;
+ }
+
+ for (final T factory : factories) {
+ final CyFileFilter cff = factory.getFileFilter();
+ logger.info("4 ### Current Filter = " +
cff.getDescription());
- final CyFileFilter cff = factory.getFileFilter();
logger.debug("Trying factory: " + factory + " with
filter: " + cff);
- if (cff.accepts(uri, category) && uri != null ) {
+ if (cff.accepts(uri, category)) {
try {
- logger.debug("Successfully found
matched factory " + factory);
- InputStream stream =
uri.toURL().openStream();
- if ( !stream.markSupported() )
- stream = new MarkSupportedInputStream(stream);
- factory.setInputStream( stream,
inputName );
+ logger.info("Successfully found matched
factory " + factory);
+ // This returns strean using proxy if
it exists.
+ InputStream stream =
streamUtil.getInputStream(uri.toURL());
+ if (!stream.markSupported()) {
+ stream = new
BufferedInputStream(stream);
+ }
+
+ factory.setInputStream(stream,
inputName);
return (R)
factory.createTaskIterator().next();
} catch (IOException e) {
logger.warn("Error opening stream to
URI: " + uri.toString(), e);
@@ -92,17 +105,17 @@
try {
if ( !stream.markSupported() )
- stream = new MarkSupportedInputStream(stream);
+ stream = new BufferedInputStream(stream);
for (T factory : factories) {
CyFileFilter cff = factory.getFileFilter();
- logger.debug("trying factory: " + factory + "
with filter: " + cff);
+ logger.debug("trying READER: " + factory + "
with filter: " + cff);
// Because we don't know who will provide the
file filter or
// what they might do with the InputStream, we
provide a copy
// of the first 2KB rather than the stream
itself.
- if
(cff.accepts(CopyInputStream.copyKBytes(stream,2), category)) {
- logger.debug("successfully matched
factory " + factory);
+ if
(cff.accepts(CopyInputStream.copyKBytes(stream,1), category)) {
+ logger.debug("successfully matched
READER " + factory);
factory.setInputStream(stream,
inputName);
return
(R)factory.createTaskIterator().next();
}
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/MarkSupportedInputStream.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/MarkSupportedInputStream.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/MarkSupportedInputStream.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -16,7 +16,7 @@
private InputStream is;
- public MarkSupportedInputStream(InputStream eis) throws IOException {
+ public MarkSupportedInputStream(final InputStream eis) throws
IOException {
super();
ByteArrayOutputStream copy = new ByteArrayOutputStream();
int read = 0;
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/VizmapReaderManagerImpl.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/VizmapReaderManagerImpl.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/VizmapReaderManagerImpl.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -1,16 +1,15 @@
package org.cytoscape.io.internal.read;
-
import org.cytoscape.io.DataCategory;
import org.cytoscape.io.read.InputStreamTaskFactory;
import org.cytoscape.io.read.VizmapReader;
import org.cytoscape.io.read.VizmapReaderManager;
+import org.cytoscape.io.util.StreamUtil;
+public class VizmapReaderManagerImpl extends
GenericReaderManager<InputStreamTaskFactory, VizmapReader> implements
+ VizmapReaderManager {
-public class VizmapReaderManagerImpl extends
GenericReaderManager<InputStreamTaskFactory, VizmapReader>
- implements VizmapReaderManager {
-
- public VizmapReaderManagerImpl() {
- super(DataCategory.VIZMAP);
- }
+ public VizmapReaderManagerImpl(final StreamUtil streamUtil) {
+ super(DataCategory.VIZMAP, streamUtil);
+ }
}
\ No newline at end of file
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/AbstractSessionReader.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/AbstractSessionReader.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/AbstractSessionReader.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -168,9 +168,8 @@
* @throws Exception
*/
protected void readSessionFile() throws Exception {
- if (!sourceInputStream.markSupported()) {
+ if (!sourceInputStream.markSupported())
throw new RuntimeException("Mark/Reset not supported!");
- }
if (inputStreamRead)
sourceInputStream.reset();
@@ -206,7 +205,6 @@
is = null;
}
}
-
zis.closeEntry();
}
} finally {
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/ReadUtils.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/ReadUtils.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/ReadUtils.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -96,7 +96,7 @@
// Use URLUtil to get the InputStream since we
might be using a
// proxy server
// and because pages may be cached:
- in = streamUtil.getBasicInputStream(u);
+ in = streamUtil.getInputStream(u);
} else
in = new FileInputStream(name);
} catch (IOException ioe) {
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/StreamUtilImpl.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/StreamUtilImpl.java
2011-12-14 21:06:25 UTC (rev 27792)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/StreamUtilImpl.java
2011-12-14 21:15:07 UTC (rev 27793)
@@ -40,16 +40,14 @@
public class StreamUtilImpl implements StreamUtil {
private static final String GZIP = ".gz";
-
private static final String ZIP = ".zip";
-
private static final String JAR = ".jar";
- private static int msConnectionTimeout = 2000;
- /**
- *
- */
- public static boolean STOP = false;
+ private static final int msConnectionTimeout = 2000;
+
+
+ // TODO: Inject this!
+ private Proxy cytoProxy; // ProxyHandler.getProxyServer();
/**
* Gets the an input stream given a URL.
@@ -60,46 +58,31 @@
* @throws IOException
*
*/
+ @Override
public InputStream getInputStream(URL source) throws IOException {
+ if(source == null)
+ throw new NullPointerException("Source URL is null");
+
final InputStream newIs;
+
final InputStream proxyIs;
- proxyIs = getBasicInputStream(source);
- if (source.toString().toLowerCase().endsWith(GZIP)) {
+ if(cytoProxy != null)
+ proxyIs =
source.openConnection(cytoProxy).getInputStream();
+ else
+ proxyIs = source.openStream();
+
+ // These are mainly for Session loading.
+ if (source.toString().toLowerCase().endsWith(GZIP))
newIs = new GZIPInputStream(proxyIs);
- } else if (source.toString().toLowerCase().endsWith(ZIP)) {
- // System.err.println(source.toString() + " ZIP ");
+ else if (source.toString().toLowerCase().endsWith(ZIP))
newIs = new ZipInputStream(proxyIs);
- } else if (source.toString().toLowerCase().endsWith(JAR)) {
+ else if (source.toString().toLowerCase().endsWith(JAR))
newIs = new JarInputStream(proxyIs);
- } else {
+ else
newIs = proxyIs;
- }
return newIs;
}
- /**
- * Obtain an InputStream for a given URL. Ensure proxy servers and an
input
- * stream to the real URL source is created--not a locally cached and
out of
- * date source. Proxy servers and other characteristics can cause pages
to
- * be cached.
- *
- * @param source
- * the non-null URL from which to obtain an InputStream.
- * @return InputStream from the source URL.
- * @throws IllegalStateException
- * if source is null.
- * @throws IOException
- * if a connection to the URL can't be opened or a problem
- * occurs with the InputStream.
- */
- public InputStream getBasicInputStream(URL source) throws IOException {
- if (source == null) {
- throw new IllegalStateException(
- "getBasicInputStream was given a null
'source' argument.");
- }
- URLConnection uc = getURLConnection(source);
- return uc.getInputStream();
- }
/**
* Obtain a URLConnection for a given URL. Ensure proxy servers are
@@ -113,14 +96,13 @@
* @throws IOException
* if a connection to the URL can't be opened.
*/
- public URLConnection getURLConnection(URL source) throws IOException {
- if (source == null) {
- throw new IllegalStateException(
- "getURLConnection was given a null
'source' argument.");
- }
- // TODO add proxy support back -- should be inserted as a
service
- Proxy cytoProxy = null; // ProxyHandler.getProxyServer();
+ @Override
+ public URLConnection getURLConnection(final URL source) throws
IOException {
+ if (source == null)
+ throw new NullPointerException("getURLConnection was
given a null 'source' argument.");
+
URLConnection uc = null;
+
if (cytoProxy == null) {
uc = source.openConnection();
} else {
@@ -139,70 +121,4 @@
uc.setConnectTimeout(msConnectionTimeout); // set timeout for
connection
return uc;
}
-
- // /**
- // * Download the file specified by the url string to the given File
object
- // *
- // * @param urlString
- // * @param downloadFile
- // * @param taskMonitor
- // * @return
- // * @throws IOException
- // */
- // public static void download(String urlString, File downloadFile,
- // TaskMonitor taskMonitor) throws IOException {
- // URL url = new URL(urlString);
- // InputStream is = null;
- // int maxCount = 0; // -1 if unknown
- // int progressCount = 0;
- // URLConnection conn = getURLConnection(url);
- // maxCount = conn.getContentLength();
- // is = conn.getInputStream();
- // FileOutputStream os = new FileOutputStream(downloadFile);
- // double percent = 0.0d;
- // byte[] buffer = new byte[1];
- // while (((is.read(buffer)) != -1) && !STOP) {
- // progressCount += buffer.length;
- // // Report on Progress
- // if (taskMonitor != null) {
- // percent = ((double) progressCount / maxCount) * 100.0;
- // if (maxCount == -1) { // file size unknown
- // percent = -1;
- // }
- // JTask jTask = (JTask) taskMonitor;
- // if (jTask.haltRequested()) { // abort
- // downloadFile = null;
- // taskMonitor.setStatus("Canceling the download ...");
- // taskMonitor.setPercentCompleted(100);
- // break;
- // }
- // taskMonitor.setPercentCompleted((int) percent);
- // }
- // os.write(buffer);
- // }
- // os.flush();
- // os.close();
- // is.close();
- // if (STOP) {
- // downloadFile.delete();
- // }
- // }
- //
- // /**
- // * Get the the contents of the given URL as a string.
- // *
- // * @param source
- // * @return String
- // * @throws IOException
- // */
- // public static String download(URL source) throws IOException {
- // InputStream is = getInputStream(source);
- // StringBuffer buffer = new StringBuffer();
- // int c;
- // while ((c = is.read()) != -1) {
- // buffer.append((char) c);
- // }
- // is.close();
- // return buffer.toString();
- // }
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.