inetutils4j

Helper class for internet related operations.

Лицензия

Лицензия

Категории

Категории

Сеть
Группа

Группа

com.github.fracpete
Идентификатор

Идентификатор

inetutils4j
Последняя версия

Последняя версия

0.0.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

inetutils4j
Helper class for internet related operations.
Система контроля версий

Система контроля версий

https://github.com/fracpete/inetutils4j

Скачать inetutils4j

Как подключить последнюю версию

<!-- 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"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
net.sourceforge.argparse4j : argparse4j jar 0.6.0

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 3.8.2

Модули Проекта

Данный проект не имеет модулей.

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:PASSWORD@proxy.example.com: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:PASSWORD@proxy.example.com: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:

Версии библиотеки

Версия
0.0.2
0.0.1