private byte[] downloadByteArray(URL url) throws IOException {
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestProperty("Cookie", cookies);
    if (conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return (null);

    InputStream in = conn.getInputStream();
    byte[] buf = new byte[conn.getContentLength()];
    int read, offset = 0;
    while ((read = in.read(buf, offset, buf.length - offset)) != -1) {
      offset += read;
    }
    return (buf);
  }
 /**
  * Given a DICOM object encoded as an XML document in a named file convert it to a list of
  * attributes.
  *
  * @param name the input file containing the XML document
  * @return the list of DICOM attributes
  * @exception IOException
  * @exception SAXException
  * @exception DicomException
  */
 public AttributeList getAttributeList(String name)
     throws IOException, SAXException, DicomException {
   InputStream fi = new FileInputStream(name);
   BufferedInputStream bi = new BufferedInputStream(fi);
   AttributeList list = null;
   try {
     list = getAttributeList(bi);
   } finally {
     bi.close();
     fi.close();
   }
   return list;
 }
Exemple #3
0
  public void downloadFile(String url, String savePath, String fileName) {

    try {
      URL theURL = new URL(url);
      InputStream input = theURL.openStream();
      OutputStream output = new FileOutputStream(new File(savePath, fileName));
      try {
        byte[] buffer = new byte[1024];
        int bytesRead = 0;
        while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
          output.write(buffer, 0, bytesRead);
        }
      } catch (Exception e) {
        debug(e.toString());
      } finally {
        output.close();
      }
    } catch (Exception e) {
      debug(e.toString());
    }
  }
  public static void main(String args[]) {
    try {

      URL url = new URL(args[0]);
      InputStream is = url.openStream();
      BufferedReader br = new BufferedReader(new InputStreamReader(is));

      String line;
      String buffer = "";
      while ((line = br.readLine()) != null) buffer += line;

      br.close();
      is.close();
      Object[] obj = {buffer};
      HTMLtoXML me = new HTMLtoXML();
      me.invoke(obj);
      obj = me.getOutputValues();
      System.out.println((String) obj[0]);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
    return;
  }