Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
Utils.java
Go to the documentation of this file.
1package io.github.ollama4j.utils;
2
3import java.io.ByteArrayOutputStream;
4import java.io.IOException;
5import java.io.InputStream;
6import java.net.URI;
7import java.net.URISyntaxException;
8import java.net.URL;
9
10import com.fasterxml.jackson.databind.ObjectMapper;
11import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
12
13public class Utils {
14
15 private static ObjectMapper objectMapper;
16
17 public static ObjectMapper getObjectMapper() {
18 if(objectMapper == null) {
19 objectMapper = new ObjectMapper();
20 objectMapper.registerModule(new JavaTimeModule());
21 }
22 return objectMapper;
23 }
24
25 public static byte[] loadImageBytesFromUrl(String imageUrl)
26 throws IOException, URISyntaxException {
27 URL url = new URI(imageUrl).toURL();
28 try (InputStream in = url.openStream();
29 ByteArrayOutputStream out = new ByteArrayOutputStream()) {
30 byte[] buffer = new byte[1024];
31 int bytesRead;
32 while ((bytesRead = in.read(buffer)) != -1) {
33 out.write(buffer, 0, bytesRead);
34 }
35 return out.toByteArray();
36 }
37 }
38}
static byte[] loadImageBytesFromUrl(String imageUrl)
Definition Utils.java:25
static ObjectMapper getObjectMapper()
Definition Utils.java:17