Esempio n. 1
0
  /** Met dans le cache le résultat de l'url indiquée */
  public boolean putInCache(String url) throws Exception {

    // Lecture
    MyInputStream in = null;
    try {
      in = Util.openStream(url);
      byte buf[] = in.readFully();

      // Nettoyage et Ecriture
      String id = codage(url);
      File g = new File(dir + Util.FS + id);
      g.delete();
      RandomAccessFile f = null;
      try {
        f = new RandomAccessFile(dir + Util.FS + id, "rw");
        f.write(buf);
      } finally {
        if (f != null) f.close();
      }
      aladin.trace(3, "Put in cache [" + url + "]");
      return true;
    } catch (Exception e) {
      if (aladin.levelTrace >= 3) e.printStackTrace();
    } finally {
      if (in != null) in.close();
    }

    return false;
  }
Esempio n. 2
0
  public void start(ContentHandler sax, Target target) throws IOException, SAXException {
    this.target = target;

    XMLReader parser;
    try {
      parser = spf.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException e) {
      throw new LagoonException(e.getMessage());
    }

    parser.setContentHandler(sax);
    parser.setEntityResolver(
        new EntityResolver() {
          public InputSource resolveEntity(String publicId, String systemId)
              throws SAXException, IOException {
            InputSource is = new InputSource(getSourceMan().getFileURL(systemId));

            File fil = getSourceMan().getFile(systemId);

            if (fil != null) {
              InputStream istr = new FileInputStream(fil);
              is.setByteStream(istr);
            }

            return is;
          }
        });

    exception = null;

    mis = new MyInputStream();
    mos = new MyOutputStream(mis);

    thread = new Thread(this);
    thread.start();

    parser.parse(new InputSource(mis));
    mis.close();

    try {
      thread.join(1000);
    } catch (InterruptedException e) {
    }

    if (thread.isAlive()) {
      thread.interrupt();
    }

    this.target = null;

    if (exception != null) {
      if (exception instanceof SAXException) {
        throw (SAXException) exception;
      } else if (exception instanceof IOException) {
        throw (IOException) exception;
      }
    }
  }