Package java.net

Examples of java.net.HttpURLConnection


    return sb.toString();
  }
 
  private boolean isImageEmpty(String url) {
    try{
      HttpURLConnection httpConn = (HttpURLConnection) new URL(url).openConnection();
      return httpConn.getContentLength() == 807;
    } catch(IOException e) {
      return true;
    }
  }
View Full Code Here


 
  public void saveAs(File f) throws CoverException {
    FileOutputStream fw = null;
    BufferedInputStream in = null;
    try {
      HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
      httpConn.setDoInput(true);
      in = new BufferedInputStream(httpConn.getInputStream());
 
      f.delete();
      fw = new FileOutputStream(f);
     
      int b;
View Full Code Here

              public void run() {
                  running.incrementAndGet();
                  try {
                      int read = 0;
                      int totalRead = 0;
                      HttpURLConnection conn = null;
                      InputStream in = null;

                      URL url = new URL(surl);
                      conn = (HttpURLConnection) url.openConnection();
                      in = new BufferedInputStream(conn.getInputStream(), 4096);
                      byte[] buffer = new byte[4096];
                      while ((read = in.read(buffer)) > 0) {
                          totalRead += read;
                      }
                      in.close();
                          
                      if (totalRead == conn.getContentLength()) {
                          System.out.print(".");
                      } else {
                          errors.add("got " + totalRead + " bytes. expected: " + conn.getContentLength());
                      }
                     
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
View Full Code Here

        String surl = "http://localhost:" + httpServer.getLocalPort() + "/" + file.getName();
       
       
        int read = 0;
        int totalRead = 0;
        HttpURLConnection conn = null;
        InputStream in = null;

        System.out.println("downloading large file...");
       
        URL url = new URL(surl);
        conn = (HttpURLConnection) url.openConnection();
        in = new BufferedInputStream(conn.getInputStream(), 4096);
        byte[] buffer = new byte[4096];
        while ((read = in.read(buffer)) > 0) {
            totalRead += read;
        }
        in.close();
            
        if (totalRead == conn.getContentLength()) {
            System.out.print(".");
        } else {
            errors.add("got " + totalRead + " bytes. expected: " + conn.getContentLength());
        }
       
        file.delete();
        httpServer.close();
  }         
View Full Code Here

   {
      dispatcher = EmbeddedContainer.start().getDispatcher();
      dispatcher.getRegistry().addPerRequestResource(SimpleResource.class);
      {
         URL url = createURL("/simple");
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
         @SuppressWarnings("unused")
         Object obj = conn.getContent();
      }
      EmbeddedContainer.stop();
   }
View Full Code Here

      }
      System.out.println("*****");
      {
         URL url = createURL("/redirect");
         // HttpURLConnection.setFollowRedirects(false);
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
         conn.setInstanceFollowRedirects(false);
         conn.setRequestMethod("GET");
         for (Object name : conn.getHeaderFields().keySet())
         {
            System.out.println(name);
         }
         System.out.println(conn.getResponseCode());
      }

   }
View Full Code Here

      String uriBase = "http://localhost:" + TestPortProvider.getPort() + "/test/path-param/";
      String expected = "start" + toTest + "end";
      String encoded = "start%" + Integer.toHexString(toTest).toUpperCase() + "end";
      URI uri = URI.create(uriBase + encoded);

      HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
      connection.setRequestMethod("GET");
      connection.setRequestProperty("accept", "text/plain");
      InputStream is = connection.getInputStream();
      Reader r = new InputStreamReader(is, "UTF-8");
      StringBuffer buf = new StringBuffer();
      char[] chars = new char[1024];
      int charsRead;
      while ((charsRead = r.read(chars)) != -1)
View Full Code Here

              public void run() {
                  running.incrementAndGet();
                  try {
                      int read = 0;
                      int totalRead = 0;
                      HttpURLConnection conn = null;
                      InputStream in = null;

                      URL url = new URL(surl);
                      conn = (HttpURLConnection) url.openConnection();
                      in = new BufferedInputStream(conn.getInputStream(), 4096);
                      byte[] buffer = new byte[4096];
                      while ((read = in.read(buffer)) > 0) {
                          totalRead += read;
                      }
                      in.close();
                          
                      if (totalRead == conn.getContentLength()) {
                          System.out.print(".");
                      } else {
                          errors.add("got " + totalRead + " bytes. expected: " + conn.getContentLength());
                      }
                     
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
View Full Code Here

        String surl = "http://localhost:" + httpServer.getLocalPort() + "/" + file.getName();
       
       
        int read = 0;
        int totalRead = 0;
        HttpURLConnection conn = null;
        InputStream in = null;

        System.out.println("downloading large file...");
       
        URL url = new URL(surl);
        conn = (HttpURLConnection) url.openConnection();
        in = new BufferedInputStream(conn.getInputStream(), 4096);
        byte[] buffer = new byte[4096];
        while ((read = in.read(buffer)) > 0) {
            totalRead += read;
        }
        in.close();
            
        if (totalRead == conn.getContentLength()) {
            System.out.print(".");
        } else {
            errors.add("got " + totalRead + " bytes. expected: " + conn.getContentLength());
        }
       
        file.delete();
        httpServer.close();
  }         
View Full Code Here

     * PDFBox.
     */
    public void testExportSingleSimplePageAsPDF() throws Exception
    {
        URL url = new URL("http://localhost:8080/xwiki/bin/export/Main/WebHome?format=pdf");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        InputStream is = connection.getInputStream();
        PDDocument pdd = PDDocument.load(is);
        PDFTextStripper stripper = new PDFTextStripper();
        String text = stripper.getText(pdd);
        pdd.close();
        is.close();
View Full Code Here

TOP

Related Classes of java.net.HttpURLConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.