Exemple #1
0
  /**
   * Parse a repository document.
   *
   * @param url
   * @throws IOException
   * @throws XmlPullParserException
   * @throws Exception
   */
  void parseDocument(URL url) throws IOException, XmlPullParserException, Exception {
    if (!visited.contains(url)) {
      visited.add(url);
      try {
        System.out.println("Visiting: " + url);
        InputStream in = null;

        if (url.getPath().endsWith(".zip")) {
          ZipInputStream zin = new ZipInputStream(url.openStream());
          ZipEntry entry = zin.getNextEntry();
          while (entry != null) {
            if (entry.getName().equals("repository.xml")) {
              in = zin;
              break;
            }
            entry = zin.getNextEntry();
          }
        } else {
          in = url.openStream();
        }
        Reader reader = new InputStreamReader(in);
        XmlPullParser parser = new KXmlParser();
        parser.setInput(reader);
        parseRepository(parser);
      } catch (MalformedURLException e) {
        System.out.println("Cannot create connection to url");
      }
    }
  }
 private void doImportFromURL(HttpServletRequest req, HttpServletResponse resp)
     throws IOException, ServletException {
   URL source = getSourceURL();
   IOUtilities.pipe(
       source.openStream(),
       new FileOutputStream(new File(getStorageDirectory(), FILE_DATA), true),
       true,
       true);
   completeTransfer(req, resp);
 }
Exemple #3
0
  /** Create a FILE object to read from the specified URL. */
  public static FILE open(URL url) {
    try {
      InputStream urlInputStream = url.openStream();
      // urlConnection.getInputStream();

      // System.out.println("open(URL) urlInputStream " + urlInputStream);

      return new FILE(urlInputStream);
    } catch (Exception e) {
      if (debug) {
        System.out.println("open(URL) exception " + e);
      }
      setException(e);

      return null;
    }
  }