public static String readSwfStreamToString(InputStream is) throws IOException { try { final byte[] bytes = new byte[2048]; // read the first 8 bytes : // 3 bytes - signature // 1 byte - version // 4 bytes - file length if (readBytes(is, bytes, 8) != 8) { throw new IOException("Error reading from stream"); } if (bytes[0] == 'C' && bytes[1] == 'W' && bytes[2] == 'S') { bytes[0] = 'F'; is = new InflaterInputStream(is); } else if (bytes[0] != 'F' || bytes[1] != 'W' || bytes[2] != 'S') { throw new IOException("Invalid SWF stream"); } final StringBuilder sb = new StringBuilder(8192); sb.append(new String(bytes, 0, 8, CHARSET_NAME)); int len; while ((len = is.read(bytes)) != -1) { sb.append(new String(bytes, 0, len, CHARSET_NAME)); } return sb.toString(); } finally { try { is.close(); } catch (final Exception e) { LogUtils.processException(logger, e); } } }
private void parseFolder() throws Exception { final HttpMethod method = getMethodBuilder() .setAction("http://www.4shared.com/web/accountActions/changeDir") .setParameter("dirId", getFolderId()) .setAjax() .toPostMethod(); if (!makeRedirectedRequest(method)) { throw new ServiceConnectionProblemException(); } final Matcher matcher = getMatcherAgainstContent("\"id\":\"(.+?)\""); final List<URI> uriList = new LinkedList<URI>(); while (matcher.find()) { final String url = "http://www.4shared.com/file/" + matcher.group(1); try { uriList.add(new URI(url)); } catch (URISyntaxException e) { LogUtils.processException(logger, e); } } getPluginService().getPluginContext().getQueueSupport().addLinksToQueue(httpFile, uriList); httpFile.getProperties().put("removeCompleted", true); }