Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
FileToBase64Serializer.java
Go to the documentation of this file.
1/*
2 * Ollama4j - Java library for interacting with Ollama server.
3 * Copyright (c) 2025 Amith Koujalgi and contributors.
4 *
5 * Licensed under the MIT License (the "License");
6 * you may not use this file except in compliance with the License.
7 *
8*/
9package io.github.ollama4j.utils;
10
11import com.fasterxml.jackson.core.JsonGenerator;
12import com.fasterxml.jackson.databind.JsonSerializer;
13import com.fasterxml.jackson.databind.SerializerProvider;
14import java.io.IOException;
15import java.util.Base64;
16import java.util.Collection;
17
18public class FileToBase64Serializer extends JsonSerializer<Collection<byte[]>> {
19
20 @Override
21 public void serialize(
22 Collection<byte[]> value, JsonGenerator jsonGenerator, SerializerProvider serializers)
23 throws IOException {
24 jsonGenerator.writeStartArray();
25 for (byte[] file : value) {
26 jsonGenerator.writeString(Base64.getEncoder().encodeToString(file));
27 }
28 jsonGenerator.writeEndArray();
29 }
30}
void serialize(Collection< byte[]> value, JsonGenerator jsonGenerator, SerializerProvider serializers)