inetutils4j

Helper class for internet related operations.

License

License

Categories

Categories

Net
GroupId

GroupId

com.github.fracpete
ArtifactId

ArtifactId

inetutils4j
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

inetutils4j
Helper class for internet related operations.
Source Code Management

Source Code Management

https://github.com/fracpete/inetutils4j

Download inetutils4j

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.fracpete/inetutils4j/ -->
<dependency>
    <groupId>com.github.fracpete</groupId>
    <artifactId>inetutils4j</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.fracpete/inetutils4j/
implementation 'com.github.fracpete:inetutils4j:0.0.2'
// https://jarcasting.com/artifacts/com.github.fracpete/inetutils4j/
implementation ("com.github.fracpete:inetutils4j:0.0.2")
'com.github.fracpete:inetutils4j:jar:0.0.2'
<dependency org="com.github.fracpete" name="inetutils4j" rev="0.0.2">
  <artifact name="inetutils4j" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.fracpete', module='inetutils4j', version='0.0.2')
)
libraryDependencies += "com.github.fracpete" % "inetutils4j" % "0.0.2"
[com.github.fracpete/inetutils4j "0.0.2"]

Dependencies

compile (1)

Group / Artifact Type Version
net.sourceforge.argparse4j : argparse4j jar 0.6.0

test (1)

Group / Artifact Type Version
junit : junit jar 3.8.2

Project Modules

There are no modules declared in this project.

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:

Versions

Version
0.0.2
0.0.1