20 package net.sf.gridarta.model.face;
23 import java.io.FileNotFoundException;
24 import java.io.IOException;
25 import java.io.RandomAccessFile;
26 import java.util.HashMap;
28 import javax.swing.ImageIcon;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
41 @SuppressWarnings(
"IOResourceOpenedButNotSafelyClosed")
48 private final Map<String, Long> positions =
new HashMap<>();
54 private final RandomAccessFile
file;
62 this.file =
new RandomAccessFile(file,
"r");
72 file =
new RandomAccessFile(fileName,
"r");
81 public void addInfo(@NotNull
final String faceName,
final int pos,
final int size) {
82 positions.put(faceName, (
long) pos << 32 | (
long) size);
87 protected ImageIcon
createImage(@NotNull
final String faceName,
final long stretch) {
88 final Long position = positions.get(faceName);
89 if (position == null) {
92 final long posI = position;
95 file.seek(posI >> 32);
96 buf =
new byte[(int) posI];
98 }
catch (
final IOException e) {
101 return new ImageIcon(buf);
CollectedFaceProvider(final String fileName)
Creates a new instance.
Abstract Base class for FaceProviders which implements a memory sensitive cache.
void addInfo(@NotNull final String faceName, final int pos, final int size)
Report position and size of a face for loading it later.
CollectedFaceProvider(final File file)
Creates a new instance.
Implementation of FaceProvider which reads images from the collected PNG archive. ...
ImageIcon createImage(@NotNull final String faceName, final long stretch)
final RandomAccessFile file
The file to read from.