Skip to main content

Java Examples for adaline.report

Java code examples for the Adaline Report API using HttpClient.

Examples use Java 11+ HttpClient. No external dependencies.

Setup

import java.net.URI;
import java.net.http.*;
import java.net.http.HttpRequest.BodyPublishers;
import java.nio.file.*;

public class AdalineReportClient {
    private static final String BASE_URL = "https://api.adaline.report";
    private static final String API_KEY = "your-api-key";
    private static final HttpClient client = HttpClient.newHttpClient();

    static String apiRequest(String method, String path, String body) throws Exception {
        var builder = HttpRequest.newBuilder()
            .uri(URI.create(BASE_URL + path))
            .header("X-API-Key", API_KEY)
            .header("Content-Type", "application/json");

        if ("POST".equals(method)) {
            builder.POST(body != null ? BodyPublishers.ofString(body) : BodyPublishers.noBody());
        } else if ("DELETE".equals(method)) {
            builder.DELETE();
        } else {
            builder.GET();
        }

        var response = client.send(builder.build(), HttpResponse.BodyHandlers.ofString());
        return response.body();
    }
}

Scan a Document

static String scanDocument(String filePath) throws Exception {
    String boundary = "----Boundary" + System.currentTimeMillis();
    byte[] fileBytes = Files.readAllBytes(Path.of(filePath));
    String fileName = Path.of(filePath).getFileName().toString();

    String bodyPrefix = "--" + boundary + "\r\n"
        + "Content-Disposition: form-data; name=\"file\"; filename=\"" + fileName + "\"\r\n"
        + "Content-Type: application/octet-stream\r\n\r\n";
    String bodySuffix = "\r\n--" + boundary + "--\r\n";

    byte[] body = new byte[bodyPrefix.getBytes().length + fileBytes.length + bodySuffix.getBytes().length];
    System.arraycopy(bodyPrefix.getBytes(), 0, body, 0, bodyPrefix.getBytes().length);
    System.arraycopy(fileBytes, 0, body, bodyPrefix.getBytes().length, fileBytes.length);
    System.arraycopy(bodySuffix.getBytes(), 0, body, bodyPrefix.getBytes().length + fileBytes.length, bodySuffix.getBytes().length);

    var request = HttpRequest.newBuilder()
        .uri(URI.create(BASE_URL + "/api/v1/scan"))
        .header("X-API-Key", API_KEY)
        .header("Content-Type", "multipart/form-data; boundary=" + boundary)
        .POST(BodyPublishers.ofByteArray(body))
        .build();

    var response = client.send(request, HttpResponse.BodyHandlers.ofString());
    return response.body();
}

public static void main(String[] args) throws Exception {
    String result = scanDocument("syllabus.pdf");
    System.out.println(result);
}

List Reports

String reports = apiRequest("GET", "/api/v1/reports?page=1", null);
System.out.println(reports);

Create a Tag

String tag = apiRequest("POST", "/api/v1/tags",
    "{\"name\": \"reviewed\", \"color\": \"green\"}");
System.out.println(tag);

Share a Report

String share = apiRequest("POST", "/api/v1/reports/" + reportId + "/share", null);
System.out.println(share);
© 2026 Adaline LLC