/huanuco

S3 client

Primary LanguageJava

huanuco

Maven Central Maven Central (snapshot) Codecov Java Version

com.io7m.huanuco

JVM Platform Status
OpenJDK (Temurin) Current Linux Build (OpenJDK (Temurin) Current, Linux)
OpenJDK (Temurin) LTS Linux Build (OpenJDK (Temurin) LTS, Linux)
OpenJDK (Temurin) Current Windows Build (OpenJDK (Temurin) Current, Windows)
OpenJDK (Temurin) LTS Windows Build (OpenJDK (Temurin) LTS, Windows)

huanuco

An opinionated, shaded, modularized distribution of the S3 client from the AWS SDK.

If you don't know why you need this specifically, you probably don't. Use the AWS SDK directly.

Features

Usage

final var clients =
  new HClients();

final var configuration =
  HClientConfiguration.builder()
    .setEndpoint(URI.create(endpoint))
    .setCredentials(new HClientAccessKeys(access, secret))
    .setBucketAccessStyle(HClientBucketAccessStyle.PATH_STYLE)
    .build();

final var tempFile =
  Paths.get("/tmp/file.txt");

try (var client = clients.createClient(configuration)) {
  Files.writeString(tempFile, "Hello!\n");

  {
    final var r =
      client.execute(
        HPutObject.builder()
          .setBucket("general")
          .setContentType("text/plain")
          .setKey("example.txt")
          .setData(Files.readAllBytes(tempFile))
          .build()
      );
  }

} catch (final HException e) {
  LOG.error("{}: {}", e.errorCode(), e.getMessage());
  for (final var entry : e.attributes().entrySet()) {
    LOG.error("  {}: {}", entry.getKey(), entry.getValue());
  }
  LOG.error("Stacktrace: ", e);
}

Demo

A demo application is included.