|
@@ -5,9 +5,13 @@ import java.awt.Point;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.awt.image.DataBufferByte;
|
|
|
import java.awt.image.WritableRaster;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.nio.file.FileSystems;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
@@ -19,7 +23,13 @@ import java.util.List;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
|
+import org.apache.commons.compress.archivers.ArchiveException;
|
|
|
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
|
|
|
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
|
|
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
|
|
+import org.apache.commons.compress.compressors.CompressorOutputStream;
|
|
|
+import org.apache.commons.compress.compressors.CompressorStreamFactory;
|
|
|
+import org.apache.commons.compress.utils.IOUtils;
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.GsonBuilder;
|
|
@@ -29,7 +39,6 @@ import com.sun.corba.se.spi.ior.Writeable;
|
|
|
|
|
|
import TypeAdapter.AbstractCpsObjectAdapter;
|
|
|
import TypeAdapter.ColorAdapter;
|
|
|
-import TypeAdapter.ImageAdapter;
|
|
|
import TypeAdapter.PositionAdapter;
|
|
|
|
|
|
import classes.Category;
|
|
@@ -96,21 +105,33 @@ public class StoreController {
|
|
|
* @throws IOException
|
|
|
* exception
|
|
|
*/
|
|
|
- public void writeSaveFile(String path) throws IOException {
|
|
|
-
|
|
|
-
|
|
|
+ public void writeSaveFile(String path) throws IOException, ArchiveException {
|
|
|
+
|
|
|
+ File dst = new File(path);
|
|
|
+ File holonFile = File.createTempFile("tmp", ".json");
|
|
|
+ dst.delete();
|
|
|
+
|
|
|
+ OutputStream out = new FileOutputStream(dst);
|
|
|
+ ArchiveOutputStream stream = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP,
|
|
|
+ out);
|
|
|
|
|
|
initNumeration();
|
|
|
JsonObject file = new JsonObject();
|
|
|
initialize(MODE.COMPLETE, file);
|
|
|
storeCategory(file);
|
|
|
storeCanvas(file);
|
|
|
+ storeData(stream);
|
|
|
|
|
|
- FileWriter writer = new FileWriter(path);
|
|
|
+ FileWriter writer = new FileWriter(holonFile);
|
|
|
writer.write(gson.toJson(file));
|
|
|
-
|
|
|
writer.flush();
|
|
|
writer.close();
|
|
|
+
|
|
|
+ addFileToSave(holonFile, stream);
|
|
|
+
|
|
|
+ stream.finish();
|
|
|
+ out.close();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -346,37 +367,66 @@ public class StoreController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void storeData(ArchiveOutputStream stream) throws IOException {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ ArrayList<String> images = new ArrayList<>();
|
|
|
+ Files.newDirectoryStream(Paths.get(System.getProperty("user.home") + "/HolonGUI/Images"),
|
|
|
+ p -> p.toFile().isFile()).forEach(p -> images.add(p.toString()));
|
|
|
+ for (String str : images) {
|
|
|
+ File src = new File(str);
|
|
|
+ addFileToSave(src, stream);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private void imageToJson(JsonObject file) {
|
|
|
-// ArrayList<String> images = new ArrayList<>();
|
|
|
-// BufferedImage buffered = null;
|
|
|
-// WritableRaster raster = null;
|
|
|
-// DataBufferByte data = null;
|
|
|
-// String k = null;
|
|
|
-// JsonObject temp = new JsonObject();
|
|
|
-//
|
|
|
-// try {
|
|
|
-// Files.newDirectoryStream(Paths.get(System.getProperty("user.home") + "/HolonGUI/Images"),
|
|
|
-// p -> p.toFile().isFile()).forEach(p -> images.add(p.toString()));
|
|
|
-//
|
|
|
-// for (String str : images) {
|
|
|
-// System.out.println("aaaaa");
|
|
|
-// k = "IMAGE" + getNumerator(NUMTYPE.IMAGE);
|
|
|
-// buffered = ImageIO.read(new File(str));
|
|
|
-// raster = buffered.getRaster();
|
|
|
-// data = (DataBufferByte) raster.getDataBuffer();
|
|
|
-//
|
|
|
-// temp.add("Image", new JsonPrimitive(str.substring(str.indexOf("/HolonGUI/Images"), str.length())));
|
|
|
-// for (int i = 0; i < data.getData().length; i++) {
|
|
|
-// temp.add("" + i, new JsonPrimitive(data.getData()[i]));
|
|
|
-// System.out.println(i);
|
|
|
-// }
|
|
|
-//
|
|
|
-// file.add(k, gson.toJsonTree(temp));
|
|
|
-// }
|
|
|
-// } catch (IOException e) {
|
|
|
-// // TODO Auto-generated catch block
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
+ // ArrayList<String> images = new ArrayList<>();
|
|
|
+ // BufferedImage buffered = null;
|
|
|
+ // WritableRaster raster = null;
|
|
|
+ // DataBufferByte data = null;
|
|
|
+ // String k = null;
|
|
|
+ // JsonObject temp = new JsonObject();
|
|
|
+ //
|
|
|
+ // try {
|
|
|
+ // Files.newDirectoryStream(Paths.get(System.getProperty("user.home") +
|
|
|
+ // "/HolonGUI/Images"),
|
|
|
+ // p -> p.toFile().isFile()).forEach(p -> images.add(p.toString()));
|
|
|
+ //
|
|
|
+ // for (String str : images) {
|
|
|
+ // System.out.println("aaaaa");
|
|
|
+ // k = "IMAGE" + getNumerator(NUMTYPE.IMAGE);
|
|
|
+ // buffered = ImageIO.read(new File(str));
|
|
|
+ // raster = buffered.getRaster();
|
|
|
+ // data = (DataBufferByte) raster.getDataBuffer();
|
|
|
+ //
|
|
|
+ // temp.add("Image", new
|
|
|
+ // JsonPrimitive(str.substring(str.indexOf("/HolonGUI/Images"),
|
|
|
+ // str.length())));
|
|
|
+ // for (int i = 0; i < data.getData().length; i++) {
|
|
|
+ // temp.add("" + i, new JsonPrimitive(data.getData()[i]));
|
|
|
+ // System.out.println(i);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // file.add(k, gson.toJsonTree(temp));
|
|
|
+ // }
|
|
|
+ // } catch (IOException e) {
|
|
|
+ // // TODO Auto-generated catch block
|
|
|
+ // e.printStackTrace();
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addFileToSave(File src, ArchiveOutputStream stream) throws IOException {
|
|
|
+
|
|
|
+ String entryName = src.getName();
|
|
|
+ ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
|
|
|
+ stream.putArchiveEntry(entry);
|
|
|
+
|
|
|
+ BufferedInputStream input = new BufferedInputStream(new FileInputStream(src));
|
|
|
+
|
|
|
+ IOUtils.copy(input, stream);
|
|
|
+ input.close();
|
|
|
+ stream.closeArchiveEntry();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|