com.github.mike10004:imnetio-helper

Helper library for common computing tasks

License

License

Categories

Categories

Net
GroupId

GroupId

com.github.mike10004
ArtifactId

ArtifactId

imnetio-helper
Last Version

Last Version

10.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Helper library for common computing tasks

Download imnetio-helper

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
com.google.guava : guava jar 23.6-jre
org.apache.httpcomponents : httpclient jar 4.5
com.google.code.findbugs : jsr305 jar 3.0.1

test (6)

Group / Artifact Type Version
junit : junit jar 4.12
com.github.tomakehurst : wiremock jar 1.56
org.slf4j : slf4j-jdk14 jar 1.7.25
org.easymock : easymock jar 3.4
org.apache.commons : commons-lang3 jar 3.5
javax.xml.bind : jaxb-api jar 2.2.11

Project Modules

There are no modules declared in this project.

Travis build status AppVeyor status Maven Central

Common Helper Libraries

Libraries that help with some common computing tasks in Java. They are:

  • imnetio-helper: imaging, networking, and I/O
  • ormlite-helper and ormlite-helper-testtools: help with ORMLite and database unit/integration testing
  • native-helper: help with platform-dependent tasks like subprocesses and platform-specific filesystem conventions

Imaging, Networking, and I/O

Imaging

Want to get an image's dimensions without buffering all the pixels?

Dimension dim = ImageInfos.readImageSize(imageBytes);
System.out.format("%d x %d", dim.width, dim.height);

Networking

Want to download something but handle various error conditions (unknown host, 404) the same way? Don't try java.net.URLConnection, where you'll get the unknown host exception on URL.openConnection(), or if you make it past that, have to catch an I/O exception on 4xx and 5xx errors and read from the error stream. Just do this instead:

HttpRequester requester = HttpRequests.newRequester();
ResponseData responseData = requester.retrieve("http://example.com");
System.out.println("HTTP response " + responseData.code);
System.out.println(new String(responseData.data));

I/O

Want to read from the first good input stream out of multiple potentially broken streams?

ByteSource first = ByteSources.broken();
byte[] bytes = { (byte) 1, (byte) 2, (byte) 3, (byte) 4};
ByteSource other = ByteSource.wrap(bytes);
ByteSource result = ByteSources.or(first, other);
System.out.println(Arrays.toString(result.toByteArray())); // [1, 2, 3, 4]

ORMLite helper

Doing some quick database work? This might help you:

DatabaseContext db = new DefaultDatabaseContext(new H2MemoryConnectionSource());
try {
    db.getTableUtils().createTable(Customer.class);
    Customer customer = new Customer("Jane Doe", 123);
    db.getDao(Customer.class).create(customer);
} finally {
    db.closeConnections(false); // 'true' to swallow exception on close
}

Native

Want the pathname of the directory where system configuration files are?

File dir = Platforms.getPlatform().getSystemConfigDir();
System.out.println(dir); 

...prints /etc on Linux and value of %ProgramData% environment variable on Windows.

Want to launch a subprocess and capture the output as strings?

// <String, String> parameters refer to type of captured stdout and stderr data
ProcessResult<String, String> result;
try (ScopedProcessTracker processTracker = new ScopedProcessTracker()) {
    result = Subprocess.running("echo")
            .arg("hello, world")
            .build()
            .launcher(processTracker)
            .outputStrings(Charset.defaultCharset())
            .launch()
            .await();
}
System.out.println(result.content().stdout()); // prints "hello, world"

How do I build it?

Prerequisites

The build system must have Maven 3.0+ installed. On Windows, you must have Perl installed and perl.exe on the system path. Visit strawberryperl.com for free Perl.

On Linux, make sure the libaio1 (Linux kernel asynchronous I/O access library) package is installed, or else the MySQL integration tests will fail.

The MySQL distribution dependency is platform-dependent and Maven central may not host an artifact corresponding to your platform. If that is the case, you can download a MySQL tarball release, re-package it into a zip file, and install it to your local repository. For example:

$ mvn install:install-file -DartifactId=mysql-dist -DgroupId=com.jcabi \
    -Dversion=5.5.41 -Dclassifier=myoperatingsystem-amd64 -Dpackaging=zip \
    -Dfile=/path/to/downloaded/mysql-dist-5.5.41-myoperatingsystem-amd64.zip

Add a profile to your $HOME/.m2/settings.xml that only gets activated when your platform is detected.

Build

Execute

$ mvn install

in the parent project directory.

Versions

Version
10.0.0
9.0.0
8.1.0
8.0.5
8.0.4
8.0.3
8.0.2
8.0.1
8.0.0
7.2.0
7.1.0
7.0.2
7.0.1
7.0.0
6.0.0
5.1.0
5.0.0
4.2.3
4.2.2
4.2.1
4.2.0
4.1.2
4.1.1
4.1.0
4.0.0