20 package net.sf.gridarta.model.collectable;
22 import java.io.BufferedWriter;
24 import java.io.FileInputStream;
25 import java.io.FileNotFoundException;
26 import java.io.FileOutputStream;
27 import java.io.IOException;
28 import java.io.OutputStream;
29 import java.io.OutputStreamWriter;
30 import java.io.Writer;
31 import java.nio.ByteBuffer;
32 import java.nio.channels.FileChannel;
33 import java.nio.charset.Charset;
38 import net.
sf.japi.swing.action.ActionBuilder;
39 import net.
sf.japi.swing.action.ActionBuilderFactory;
40 import net.
sf.japi.swing.misc.Progress;
41 import org.jetbrains.annotations.NotNull;
56 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
91 public void collect(@NotNull
final Progress progress, @NotNull
final File collectedDirectory)
throws IOException {
103 private void collectImageFile(@NotNull
final Progress progress, @NotNull
final File collectedDirectory)
throws IOException {
105 try (FileOutputStream fos =
new FileOutputStream(file)) {
106 try (FileChannel outChannel = fos.getChannel()) {
107 final int numOfFaceObjects = faceObjects.
size();
109 final ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
110 final Charset charset = Charset.forName(
"ISO-8859-1");
112 for (
final FaceObject faceObject : faceObjects) {
113 final String face = faceObject.getFaceName();
114 final String path = archFaceProvider.
getFilename(face);
116 try (FileInputStream fin =
new FileInputStream(path)) {
117 final FileChannel inChannel = fin.getChannel();
118 final long imageSize = inChannel.size();
120 byteBuffer.put((
"IMAGE " + (faceObjects.isIncludeFaceNumbers() ? i +
" " :
"") + imageSize +
" " + face +
"\n").getBytes(charset));
122 outChannel.write(byteBuffer);
123 inChannel.transferTo(0L, imageSize, outChannel);
125 }
catch (
final FileNotFoundException ignored) {
126 ACTION_BUILDER.showMessageDialog(progress.getParentComponent(),
"archCollectErrorFileNotFound", path);
128 }
catch (
final IOException e) {
129 ACTION_BUILDER.showMessageDialog(progress.getParentComponent(),
"archCollectErrorIOException", path, e);
133 if (i++ % 100 == 0) {
134 progress.setValue(i);
137 progress.setValue(faceObjects.size());
148 private void collectTreeFile(@NotNull
final Progress progress, @NotNull
final File collectedDirectory)
throws IOException {
158 private void collectBmapsFile(@NotNull
final Progress progress, @NotNull
final File collectedDirectory)
throws IOException {
170 private void collectFile(@NotNull
final Progress progress, @NotNull
final File file, @NotNull
final String label, @NotNull
final String format)
throws IOException {
171 try (OutputStream fos =
new FileOutputStream(file)) {
172 try (Writer osw =
new OutputStreamWriter(fos)) {
173 try (Writer bw =
new BufferedWriter(osw)) {
174 final int numOfFaceObjects = faceObjects.
size();
175 progress.setLabel(label, numOfFaceObjects);
177 for (
final FaceObject faceObject : faceObjects) {
178 final String path = faceObject.getPath();
179 final String face = faceObject.getFaceName();
180 bw.append(String.format(format, i, path, face)).append(
'\n');
181 if (i++ % 100 == 0) {
182 progress.setValue(i);
185 progress.setValue(numOfFaceObjects);
void collectImageFile(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Creates the image file.
Common interface for FaceObject.
int size()
Get the number of objects.
String getFilename(@NotNull final String faceName)
Get the filename for a face.
A Collectable has information that can be collected.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Base package of all Gridarta classes.
final FaceObjects faceObjects
The FaceObjects being collected.
FaceObjectsCollectable(@NotNull final FaceObjects faceObjects, @NotNull final ArchFaceProvider archFaceProvider)
Creates a new instance.
void collectBmapsFile(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Creates the bmaps file.
FaceObjects is a container for FaceObjects.
Utility class for ActionBuilder related functions.
void collect(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Collects information.the progress to report progress to the destination directory to collect data to ...
The face is the appearance of an object.
void collectFile(@NotNull final Progress progress, @NotNull final File file, @NotNull final String label, @NotNull final String format)
Creates an output file containing all faces.
Implementation of FaceProvider which reads images from the arch directory.
A Collectable that creates the atrinik.0/crossfire.0/daimonin.0 files which contains all defined face...
static final ActionBuilder ACTION_BUILDER
The ActionBuilder instance.
final ArchFaceProvider archFaceProvider
The ArchFaceProvider to use for collection.
void collectTreeFile(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Creates the tree file.