GithubHelp home page GithubHelp logo

fracpete / inetutils4j Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 30 KB

Helper classes for internet related operations, like proxy settings and downloading files.

License: GNU General Public License v3.0

Java 100.00%
internet downloader proxy-configuration java

inetutils4j's Introduction

inetutils4j

Helper classes for internet related operations, like proxy settings and downloading files.

API

Proxy

There are three types of proxies supported:

  • HTTP
  • FTP
  • SOCKS

Use the com.github.fracpete.inetutils4j.api.Proxy class to set or query current proxy settings:

import com.github.fracpete.inetutils4j.api.Proxy;
import com.github.fracpete.inetutils4j.api.Proxy.ProxyType;
...
Proxy.setProxy(ProxyType.HTTP, "http://proxy.example.com", 3128);

You can also supply the port in the URL:

import com.github.fracpete.inetutils4j.api.Proxy;
import com.github.fracpete.inetutils4j.api.Proxy.ProxyType;
...
Proxy.setProxy(ProxyType.HTTP, "http://proxy.example.com:3128");

If you need to supply a user and password for the proxy, use this:

import com.github.fracpete.inetutils4j.api.Proxy;
import com.github.fracpete.inetutils4j.api.Proxy.ProxyType;
...
Proxy.setProxy(ProxyType.HTTP, "http://USER:[email protected]:3128");

Downloading files

The download method of the com.github.fracpete.inetutils4j.api.Internet class performs the actual download. Whether you want to capture any output from running it in verbose, is handled by an instance of com.github.fracpete.inetutils4j.core.OutputCapture. Use NullCapture to avoid any output or DefaultCapture to simply output to stdout/stderr.

import com.github.fracpete.inetutils4j.api.Internet;
import com.github.fracpete.inetutils4j.core.DefaultCapture;
...
String msg = Internet.download(
  "http://myserver.example.com/myfile.txt",
  "/home/user/myfile.txt",
  true,
  new DefaultCapture());
if (msg != null)
  System.err.println("An error occurred:\n" + msg);

NB: The download method automatically handles redirects.

Downloading binary data

The binaryContent method of the com.github.fracpete.inetutils4j.api.Internet class performs the download of a remote resource. Whether you want to capture any output from running it in verbose, is handled by an instance of com.github.fracpete.inetutils4j.core.OutputCapture. Use NullCapture to avoid any output or DefaultCapture to simply output to stdout/stderr.

import com.github.fracpete.inetutils4j.api.Internet;
import com.github.fracpete.inetutils4j.core.DefaultCapture;
...
byte[] data = Internet.binaryContent(
  "http://myserver.example.com/myfile.txt",
  true,
  new DefaultCapture());
if (data == null)
  System.err.println("An error occurred!");
else
  System.out.println(data.length + " bytes downloaded");

NB: The binaryContent method automatically handles redirects.

Downloading textual data

The textualContent method of the com.github.fracpete.inetutils4j.api.Internet class performs the download of a remote resource. Whether you want to capture any output from running it in verbose, is handled by an instance of com.github.fracpete.inetutils4j.core.OutputCapture. Use NullCapture to avoid any output or DefaultCapture to simply output to stdout/stderr.

import com.github.fracpete.inetutils4j.api.Internet;
import com.github.fracpete.inetutils4j.core.DefaultCapture;
...
String html = Internet.textualContent(
  "http://myserver.example.com/myfile.txt",
  "ISO-8859-1",
  true,
  new DefaultCapture());
if (html == null)
  System.err.println("An error occurred!");
else
  System.out.println(html);

NB: The textualContent method automatically handles redirects.

Command-line tools

Download

usage: com.github.fracpete.inetutils4j.tools.Download
       [-h] -r REMOTE -l LOCAL [-v] [--http_proxy HTTP_PROXY]
       [--ftp_proxy FTP_PROXY] [--socks_proxy SOCKS_PROXY]

Allows the download of remote files.
If proxies should require user/password, then  you need to include these in
the URL. For instance, for a HTTP proxy, use this format:
  http://USER:[email protected]:3128/

optional arguments:
  -h, --help             show this help message and exit
  -r REMOTE, --remote REMOTE
                         The URL of the remote file to download
  -l LOCAL, --local LOCAL
                         The local file to download the remote file to.
  -v, --verbose          increase verbosity
  --http_proxy HTTP_PROXY
                         The URL of the HTTP proxy to use (including port)
  --ftp_proxy FTP_PROXY  The URL of the FTP proxy to use (including port)
  --socks_proxy SOCKS_PROXY
                         The URL of the socks proxy to use (including port)

Maven

Add the following artifact to your dependencies of your pom.xml:

    <dependency>
      <groupId>com.github.fracpete</groupId>
      <artifactId>inetutils4j</artifactId>
      <version>0.0.2</version>
    </dependency>

Releases

The following releases are available:

inetutils4j's People

Contributors

dependabot[bot] avatar fracpete avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.