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.Buffer;
32 import java.nio.ByteBuffer;
33 import java.nio.channels.FileChannel;
34 import java.nio.charset.Charset;
35 import java.nio.charset.StandardCharsets;
40 import net.
sf.japi.swing.action.ActionBuilder;
41 import net.
sf.japi.swing.action.ActionBuilderFactory;
42 import net.
sf.japi.swing.misc.Progress;
43 import org.jetbrains.annotations.NotNull;
58 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
93 public void collect(@NotNull
final Progress progress, @NotNull
final File collectedDirectory)
throws IOException {
105 private void collectImageFile(@NotNull
final Progress progress, @NotNull
final File collectedDirectory)
throws IOException {
107 try (FileOutputStream fos =
new FileOutputStream(file)) {
108 try (FileChannel outChannel = fos.getChannel()) {
111 final ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
112 final Charset charset = StandardCharsets.ISO_8859_1;
115 final String face = faceObject.getFaceName();
118 try (FileInputStream fin =
new FileInputStream(path)) {
119 final FileChannel inChannel = fin.getChannel();
120 final long imageSize = inChannel.size();
121 ((Buffer) byteBuffer).clear();
123 ((Buffer) byteBuffer).flip();
124 outChannel.write(byteBuffer);
125 inChannel.transferTo(0L, imageSize, outChannel);
127 }
catch (
final FileNotFoundException ignored) {
128 ACTION_BUILDER.showMessageDialog(progress.getParentComponent(),
"archCollectErrorFileNotFound", path);
130 }
catch (
final IOException e) {
131 ACTION_BUILDER.showMessageDialog(progress.getParentComponent(),
"archCollectErrorIOException", path, e);
135 if (i++ % 100 == 0) {
136 progress.setValue(i);
150 private void collectTreeFile(@NotNull
final Progress progress, @NotNull
final File collectedDirectory)
throws IOException {
160 private void collectBmapsFile(@NotNull
final Progress progress, @NotNull
final File collectedDirectory)
throws IOException {
172 private void collectFile(@NotNull
final Progress progress, @NotNull
final File file, @NotNull
final String label, @NotNull
final String format)
throws IOException {
173 try (OutputStream fos =
new FileOutputStream(file)) {
174 try (Writer osw =
new OutputStreamWriter(fos)) {
175 try (Writer bw =
new BufferedWriter(osw)) {
177 progress.setLabel(label, numOfFaceObjects);
180 final String path = faceObject.getPath();
181 final String face = faceObject.getFaceName();
182 bw.append(String.format(format, i, path, face)).append(
'\n');
183 if (i++ % 100 == 0) {
184 progress.setValue(i);
187 progress.setValue(numOfFaceObjects);