public static InputStream getInputStream(URI uri) throws IOException { String requestType = getRequestTypes(); URLConnection conn = uri.toURL().openConnection(); conn.addRequestProperty("Accept", requestType); // if (IOProperties.getInstance().isConnectionAcceptHTTPCompression()) { // conn.setRequestProperty("Accept-Encoding","gzip, deflate"); // } // conn.setConnectTimeout(IOProperties.getInstance().getConnectionTimeout()); InputStream is; if ("gzip".equals(conn.getContentEncoding())) { // test works OK even if CE is null logger.debug("URL connection input stream is compressed using gzip"); is = new BufferedInputStream(new GZIPInputStream(conn.getInputStream())); } else if ("deflate".equals(conn.getContentEncoding())) { logger.debug("URL connection input stream is compressed using deflate"); is = new BufferedInputStream(new InflaterInputStream(conn.getInputStream(), new Inflater(true))); } else { is = new BufferedInputStream(conn.getInputStream()); } if (uri.toString().endsWith(".zip")) { ZipInputStream zis = new ZipInputStream(is); zis.getNextEntry(); is = new BufferedInputStream(zis); } return is; }
public static InputStream getInputStream(URI uri) throws IOException { String requestType = getRequestTypes(); URLConnection conn = uri.toURL().openConnection(); conn.addRequestProperty("Accept", requestType); // if (IOProperties.getInstance().isConnectionAcceptHTTPCompression()) { // conn.setRequestProperty("Accept-Encoding","gzip, deflate"); // } // conn.setConnectTimeout(IOProperties.getInstance().getConnectionTimeout()); InputStream is; if ("gzip".equals(conn.getContentEncoding())) { // test works OK even if CE is null logger.debug("URL connection input stream is compressed using gzip"); is = new BufferedInputStream(new GZIPInputStream(conn.getInputStream())); } else if ("deflate".equals(conn.getContentEncoding())) { logger.debug("URL connection input stream is compressed using deflate"); is = new BufferedInputStream(new InflaterInputStream(conn.getInputStream(), new Inflater(true))); } else { is = new BufferedInputStream(conn.getInputStream()); } if (uri.toString().endsWith(".zip")) { ZipInputStream zis = new ZipInputStream(is); zis.getNextEntry(); is = new BufferedInputStream(zis); } return is; }
public static InputStream getInputStream(URI uri) throws IOException { String requestType = getRequestTypes(); URLConnection conn = uri.toURL().openConnection(); conn.addRequestProperty("Accept", requestType); if (IOProperties.getInstance().isConnectionAcceptHTTPCompression()) { conn.setRequestProperty("Accept-Encoding","gzip, deflate"); } conn.setConnectTimeout(IOProperties.getInstance().getConnectionTimeout()); InputStream is; if ("gzip".equals(conn.getContentEncoding())) { // test works OK even if CE is null logger.debug("URL connection input stream is compressed using gzip"); is = new BufferedInputStream(new GZIPInputStream(conn.getInputStream())); } else if ("deflate".equals(conn.getContentEncoding())) { logger.debug("URL connection input stream is compressed using deflate"); is = new BufferedInputStream(new InflaterInputStream(conn.getInputStream(), new Inflater(true))); } else { is = new BufferedInputStream(conn.getInputStream()); } if (uri.toString().endsWith(".zip")) { ZipInputStream zis = new ZipInputStream(is); zis.getNextEntry(); is = new BufferedInputStream(zis); } return is; }
public static InputStream getInputStream(URI uri) throws IOException { String requestType = getRequestTypes(); URLConnection conn = uri.toURL().openConnection(); conn.addRequestProperty("Accept", requestType); if (IOProperties.getInstance().isConnectionAcceptHTTPCompression()) { conn.setRequestProperty("Accept-Encoding","gzip, deflate"); } conn.setConnectTimeout(IOProperties.getInstance().getConnectionTimeout()); InputStream is; if ("gzip".equals(conn.getContentEncoding())) { // test works OK even if CE is null logger.debug("URL connection input stream is compressed using gzip"); is = new BufferedInputStream(new GZIPInputStream(conn.getInputStream())); } else if ("deflate".equals(conn.getContentEncoding())) { logger.debug("URL connection input stream is compressed using deflate"); is = new BufferedInputStream(new InflaterInputStream(conn.getInputStream(), new Inflater(true))); } else { is = new BufferedInputStream(conn.getInputStream()); } if (uri.toString().endsWith(".zip")) { ZipInputStream zis = new ZipInputStream(is); zis.getNextEntry(); is = new BufferedInputStream(zis); } return is; }