├── doc ├── package-list ├── script.js ├── fr │ └── sofianelecubeur │ │ └── dataserializer │ │ ├── base64 │ │ ├── package-frame.html │ │ ├── package-tree.html │ │ └── package-summary.html │ │ ├── util │ │ ├── package-frame.html │ │ ├── package-tree.html │ │ └── package-summary.html │ │ ├── package-frame.html │ │ ├── TextDeserializer.html │ │ └── TextSerializer.html ├── overview-frame.html ├── index.html ├── constant-values.html ├── allclasses-noframe.html ├── allclasses-frame.html ├── overview-summary.html ├── index-files │ ├── index-11.html │ ├── index-12.html │ ├── index-1.html │ ├── index-13.html │ ├── index-9.html │ ├── index-10.html │ ├── index-17.html │ ├── index-8.html │ ├── index-5.html │ └── index-16.html ├── deprecated-list.html └── help-doc.html ├── .gitignore ├── src ├── main │ └── java │ │ └── fr │ │ └── sofianelecubeur │ │ └── dataserializer │ │ ├── TextSerializer.java │ │ ├── TextDeserializer.java │ │ ├── CompilationType.java │ │ ├── FileSerializer.java │ │ ├── util │ │ ├── Pair.java │ │ └── HashUtils.java │ │ ├── BinaryFileDeserializer.java │ │ ├── Deserializer.java │ │ ├── Serializer.java │ │ ├── CompressionUtils.java │ │ ├── FileSerializerBuilder.java │ │ ├── HashTextSerializer.java │ │ ├── FileInfo.java │ │ ├── FileDeserializerBuilder.java │ │ ├── JsonFileDeserializer.java │ │ ├── base64 │ │ └── ExportPriv.java │ │ ├── Base64FileDeserializer.java │ │ ├── BinaryFileSerializer.java │ │ ├── Base64FileSerializer.java │ │ ├── JsonFileSerializer.java │ │ ├── CSVFileDeserializer.java │ │ └── CSVFileSerializer.java └── test │ └── java │ └── fr │ └── sofianelecubeur │ └── dataserializer │ ├── TestDeserializer.java │ └── TestSerializer.java ├── DataSerializer.iml ├── pom.xml └── README.md /doc/package-list: -------------------------------------------------------------------------------- 1 | fr.sofianelecubeur.dataserializer 2 | fr.sofianelecubeur.dataserializer.base64 3 | fr.sofianelecubeur.dataserializer.util 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build.xml 2 | 3 | /target 4 | /dependency-reduced-pom.xml 5 | */target 6 | */dependency-reduced-pom.xml 7 | 8 | .*.sw[a-p] 9 | 10 | /build 11 | /bin 12 | /dist 13 | /manifest.mf 14 | 15 | /.DS_Store 16 | 17 | *.iml 18 | *.ipr 19 | *.iws 20 | .idea/ -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/TextSerializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | /** 4 | * Created by Sofiane on 25/06/2017. 5 | * 6 | * @author Sofiane 7 | */ 8 | public interface TextSerializer { 9 | 10 | T compile(K str); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/TextDeserializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | /** 4 | * Created by Sofiane on 25/06/2017. 5 | * 6 | * @author Sofiane 7 | */ 8 | public interface TextDeserializer { 9 | 10 | String decompile(T o); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/CompilationType.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | /** 4 | * Created by SofianeLeCubeur on 24/06/2017. 5 | * 6 | * @author SofianeLeCubeur 7 | */ 8 | public enum CompilationType { 9 | JSON(), 10 | BINARY(), 11 | BASE64(), 12 | HASH(), 13 | CVS(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/FileSerializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | /** 7 | * Created by SofianeLeCubeur on 24/06/2017. 8 | * 9 | * @author SofianeLeCubeur 10 | */ 11 | public interface FileSerializer { 12 | 13 | void write(byte[] o) throws IOException; 14 | void writeInt(Integer o) throws IOException; 15 | void writeShort(Short o) throws IOException; 16 | void writeLong(Long o) throws IOException; 17 | void writeDouble(Double o) throws IOException; 18 | void writeFloat(Float o) throws IOException; 19 | void writeBoolean(Boolean o) throws IOException; 20 | void writeUTF(String o) throws IOException; 21 | void writeObject(Object o) throws IOException; 22 | 23 | long compile(File file) throws IOException; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /doc/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /doc/fr/sofianelecubeur/dataserializer/base64/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | fr.sofianelecubeur.dataserializer.base64 7 | 8 | 9 | 10 | 11 | 12 |

fr.sofianelecubeur.dataserializer.base64

13 |
14 |

Classes

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /doc/fr/sofianelecubeur/dataserializer/util/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | fr.sofianelecubeur.dataserializer.util 7 | 8 | 9 | 10 | 11 | 12 |

fr.sofianelecubeur.dataserializer.util

13 |
14 |

Classes

15 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /doc/overview-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Overview List 7 | 8 | 9 | 10 | 11 | 12 | 13 | 21 |

 

22 | 23 | 24 | -------------------------------------------------------------------------------- /DataSerializer.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/util/Pair.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer.util; 2 | 3 | /** 4 | * Created by Sofiane on 09/11/2017. 5 | * 6 | * Store 2 values in a single variable 7 | * @author Sofiane 8 | */ 9 | public class Pair { 10 | 11 | private L left; 12 | private R right; 13 | 14 | public Pair(L left, R right) { 15 | this.left = left; 16 | this.right = right; 17 | } 18 | 19 | public L getLeft() { 20 | return left; 21 | } 22 | 23 | public void setLeft(L left) { 24 | this.left = left; 25 | } 26 | 27 | public R getRight() { 28 | return right; 29 | } 30 | 31 | public void setRight(R right) { 32 | this.right = right; 33 | } 34 | 35 | @Override 36 | public boolean equals(Object o) { 37 | if (this == o) return true; 38 | if (o == null || getClass() != o.getClass()) return false; 39 | 40 | Pair pair = (Pair) o; 41 | 42 | if (left != null ? !left.equals(pair.left) : pair.left != null) return false; 43 | return right != null ? right.equals(pair.right) : pair.right == null; 44 | } 45 | 46 | @Override 47 | public int hashCode() { 48 | int result = left != null ? left.hashCode() : 0; 49 | result = 31 * result + (right != null ? right.hashCode() : 0); 50 | return result; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/util/HashUtils.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer.util; 2 | 3 | import fr.sofianelecubeur.dataserializer.HashTextSerializer; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * Created by Sofiane on 26/09/2017. 9 | * 10 | * @author Sofiane 11 | */ 12 | public class HashUtils { 13 | 14 | private static final HashTextSerializer hasher = new HashTextSerializer(UUID.randomUUID(), HashTextSerializer.Hash.SHA1); 15 | 16 | public static String sha1(byte[] array){ 17 | hasher.set(HashTextSerializer.Hash.SHA1); 18 | return hasher.compile(array); 19 | } 20 | 21 | public static String sha1(String s){ 22 | hasher.set(HashTextSerializer.Hash.SHA1); 23 | return hasher.compile(s); 24 | } 25 | 26 | public static String sha256(byte[] array){ 27 | hasher.set(HashTextSerializer.Hash.SHA256); 28 | return hasher.compile(array); 29 | } 30 | 31 | public static String sha256(String s){ 32 | hasher.set(HashTextSerializer.Hash.SHA256); 33 | return hasher.compile(s); 34 | } 35 | 36 | public static String md5(byte[] array){ 37 | hasher.set(HashTextSerializer.Hash.MD5); 38 | return hasher.compile(array); 39 | } 40 | 41 | public static String md5(String s){ 42 | hasher.set(HashTextSerializer.Hash.MD5); 43 | return hasher.compile(s); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/BinaryFileDeserializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import fr.sofianelecubeur.dataserializer.base64.Base64Coder; 4 | 5 | import java.io.*; 6 | import java.util.UUID; 7 | 8 | /** 9 | * Created by SofianeLeCubeur on 24/06/2017. 10 | * 11 | * @author SofianeLeCubeur 12 | */ 13 | public class BinaryFileDeserializer extends Deserializer { 14 | 15 | private File file; 16 | 17 | public BinaryFileDeserializer(File file, UUID identifier) throws FileNotFoundException { 18 | this(new FileInputStream(file), identifier); 19 | this.file = file; 20 | } 21 | 22 | public BinaryFileDeserializer(FileInputStream in, UUID identifier) throws FileNotFoundException { 23 | super(CompilationType.BINARY, in, identifier); 24 | } 25 | 26 | @SuppressWarnings("unchecked") 27 | public T readObject(Class clazz) throws IOException, ClassNotFoundException { 28 | ObjectInputStream in = new ObjectInputStream(this.in); 29 | Object o = in.readObject(); 30 | if(!clazz.isInstance(o)) 31 | return null; 32 | return (T) o; 33 | } 34 | 35 | public Object readObject() throws IOException, ClassNotFoundException { 36 | ObjectInputStream in = new ObjectInputStream(this.in); 37 | return in.readObject(); 38 | } 39 | 40 | public FileInfo info(){ 41 | if(this.file == null) throw new NullPointerException(); 42 | return new FileInfo(this.file); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/Deserializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.UUID; 9 | 10 | /** 11 | * Created by SofianeLeCubeur on 24/06/2017. 12 | * 13 | * @author SofianeLeCubeur 14 | * 15 | * Please, for using a new Deserializer, use {@link fr.sofianelecubeur.dataserializer.FileDeserializerBuilder} 16 | */ 17 | public abstract class Deserializer extends DataInputStream { 18 | 19 | private static Map map = new HashMap<>(); 20 | 21 | protected final CompilationType type; 22 | protected final UUID identifier; 23 | 24 | public Deserializer(CompilationType type, InputStream in, UUID identifier) { 25 | super(in); 26 | this.type = type; 27 | this.identifier = identifier; 28 | map.put(this.identifier, this); 29 | } 30 | 31 | @Override 32 | public final void close() throws IOException { 33 | map.remove(this.identifier); 34 | super.close(); 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "Deserializer[id:"+identifier+",type:"+type+"]"; 40 | } 41 | 42 | public static Deserializer find(String identifier){ 43 | return find(UUID.fromString(identifier)); 44 | } 45 | 46 | public static Deserializer find(UUID identifier){ 47 | return map.get(identifier); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/Serializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.Closeable; 4 | import java.io.IOException; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | import java.util.UUID; 8 | 9 | /** 10 | * Created by SofianeLeCubeur on 24/06/2017. 11 | * 12 | * @author SofianeLeCubeur 13 | * 14 | * Please, for using a new Serializer, use {@link fr.sofianelecubeur.dataserializer.FileSerializerBuilder} 15 | */ 16 | public abstract class Serializer implements Closeable { 17 | 18 | private static Map map = new HashMap<>(); 19 | 20 | protected final CompilationType type; 21 | protected final UUID identifier; 22 | 23 | public Serializer(CompilationType type, UUID identifier) { 24 | this.type = type; 25 | this.identifier = identifier; 26 | map.put(this.identifier, this); 27 | } 28 | 29 | public final CompilationType getCompilationType(){ 30 | return this.type; 31 | } 32 | 33 | public final UUID getIdentifier() { 34 | return this.identifier; 35 | } 36 | 37 | public void close() throws IOException { 38 | map.remove(this.identifier); 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "Serializer[id:"+identifier+",type:"+type+"]"; 44 | } 45 | 46 | public static Serializer find(String identifier){ 47 | return find(UUID.fromString(identifier)); 48 | } 49 | 50 | public static Serializer find(UUID identifier){ 51 | return map.get(identifier); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/fr/sofianelecubeur/dataserializer/TestDeserializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.StringJoiner; 6 | 7 | public class TestDeserializer { 8 | 9 | public static void main(String[] args) throws IOException, ClassNotFoundException { 10 | Base64FileDeserializer deserializer = (Base64FileDeserializer) new FileDeserializerBuilder().type(CompilationType.BASE64) 11 | .file(new File("data")).get(); 12 | System.out.println(deserializer.readInt()); 13 | System.out.println(deserializer.readUTF()); 14 | System.out.println(deserializer.readFloat()); 15 | System.out.println(deserializer.readObject()); 16 | 17 | deserializer.close(); 18 | System.out.println("------------------------"); 19 | JsonFileDeserializer deserializer1 = (JsonFileDeserializer) new FileDeserializerBuilder().type(CompilationType.JSON) 20 | .file(new File("data1")).get(); 21 | System.out.println(deserializer1.readInt("int")); 22 | System.out.println(deserializer1.readUTF("str")); 23 | System.out.println(deserializer1.readFloat("flt")); 24 | System.out.println(deserializer1.readObject("ipt")); 25 | 26 | deserializer1.close(); 27 | 28 | System.out.println("------------------------"); 29 | CSVFileDeserializer deserializer2 = (CSVFileDeserializer) new FileDeserializerBuilder().type(CompilationType.CVS) 30 | .file(new File("file.csv")).delemiter(";").type2(CSVFileSerializer.ColumnType.HORIZONTAL).get(); 31 | System.out.println("Columns: "+deserializer2.getColumnsString()); 32 | System.out.println("Rows: "+deserializer2.getRows()); 33 | System.out.println("Values: "+deserializer2.getValuesString()); 34 | 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/CompressionUtils.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.IOException; 5 | import java.util.zip.DataFormatException; 6 | import java.util.zip.Deflater; 7 | import java.util.zip.Inflater; 8 | 9 | /** 10 | * Created by Sofiane on 07/08/2017. 11 | * 12 | * @author Sofiane 13 | */ 14 | public class CompressionUtils { 15 | 16 | public static byte[] compress(byte[] data, int level){ 17 | try { 18 | Deflater deflater = new Deflater(level); 19 | deflater.setInput(data); 20 | ByteArrayOutputStream out = new ByteArrayOutputStream(data.length); 21 | deflater.finish(); 22 | byte[] buffer = new byte[1024]; 23 | while (!deflater.finished()) { 24 | int length = deflater.deflate(buffer); 25 | out.write(buffer, 0, length); 26 | } 27 | out.close(); 28 | return out.toByteArray(); 29 | } catch (IOException e) { 30 | e.printStackTrace(); 31 | } 32 | return data; 33 | } 34 | 35 | public static byte[] decompress(byte[] data){ 36 | try { 37 | Inflater inflater = new Inflater(); 38 | inflater.setInput(data); 39 | ByteArrayOutputStream out = new ByteArrayOutputStream(data.length); 40 | byte[] buffer = new byte[1024]; 41 | while (!inflater.finished()) { 42 | int length = inflater.inflate(buffer); 43 | out.write(buffer, 0, length); 44 | } 45 | out.close(); 46 | return out.toByteArray(); 47 | }catch(Exception e){ 48 | e.printStackTrace(); 49 | } 50 | return data; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 4.0.0 5 | com.github.sofianelecubeur 6 | DataSerializer 7 | 0.0.4 8 | DataSerializer 9 | https://github.com/SofianeLeCubeur/DataSerializer 10 | Serialize and Deserialize files ! 11 | 12 | 13 | GitHub Issue Tracker 14 | https://github.com/SofianeLeCubeur/DataSerializer/issues 15 | 16 | 17 | 18 | 19 | com.googlecode.json-simple 20 | json-simple 21 | 1.1.1 22 | compile 23 | 24 | 25 | 26 | 27 | UTF-8 28 | 29 | 30 | 31 | ${project.artifactId} 32 | 33 | 34 | maven-compiler-plugin 35 | 3.2 36 | 37 | 1.8 38 | 1.8 39 | 40 | 41 | 42 | maven-assembly-plugin 43 | 44 | 45 | package 46 | 47 | single 48 | 49 | 50 | 51 | 52 | 53 | jar-with-dependencies 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/FileSerializerBuilder.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.util.UUID; 4 | 5 | /** 6 | * Created by SofianeLeCubeur on 24/06/2017. 7 | * 8 | * @author SofianeLeCubeur 9 | */ 10 | public class FileSerializerBuilder { 11 | 12 | private CompilationType type; 13 | private int length; 14 | private UUID identifier; 15 | 16 | public FileSerializerBuilder() { 17 | this.type = CompilationType.BASE64; 18 | this.length = 1024; 19 | this.identifier = UUID.randomUUID(); 20 | } 21 | 22 | /** 23 | * Set the serializer type 24 | * @param type the serialier type 25 | * @return this 26 | */ 27 | public FileSerializerBuilder type(CompilationType type){ 28 | this.type = type; 29 | 30 | return this; 31 | } 32 | 33 | /** 34 | * Use a custom buffer length 35 | * @param length the buffer length 36 | * @return this 37 | */ 38 | public FileSerializerBuilder length(int length){ 39 | this.length = length; 40 | 41 | return this; 42 | } 43 | 44 | /** 45 | * Set a custom identifier 46 | * @param identifier the custom identifier 47 | * @return this 48 | */ 49 | public FileSerializerBuilder identifier(UUID identifier){ 50 | this.identifier = identifier; 51 | 52 | return this; 53 | } 54 | 55 | /** 56 | * Build the Deserializer 57 | * @return FileSerializer 58 | */ 59 | public FileSerializer get(){ 60 | try { 61 | switch (this.type) { 62 | case JSON: 63 | return new JsonFileSerializer(this.length, this.identifier); 64 | case BINARY: 65 | return new BinaryFileSerializer(this.length, this.identifier); 66 | case BASE64: 67 | return new Base64FileSerializer(this.length, this.identifier); 68 | case CVS: 69 | return new CSVFileSerializer(this.identifier); 70 | } 71 | } catch (Exception e) { 72 | e.printStackTrace(); 73 | } 74 | return null; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/fr/sofianelecubeur/dataserializer/TestSerializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import fr.sofianelecubeur.dataserializer.util.HashUtils; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.net.InetAddress; 8 | import java.security.MessageDigest; 9 | import java.util.UUID; 10 | 11 | public class TestSerializer { 12 | 13 | public static void main(String[] args) throws IOException { 14 | System.out.println("Starting writing data..."); 15 | Base64FileSerializer serializer = (Base64FileSerializer) new FileSerializerBuilder().type(CompilationType.BASE64).get(); 16 | serializer.writeInt(192); 17 | serializer.writeUTF("test"); 18 | serializer.writeFloat(42.5f); 19 | serializer.writeObject(InetAddress.getLocalHost()); 20 | long time = serializer.compile(new File("data")); 21 | serializer.close(); 22 | System.out.println("Finished in "+(time / 1000)+"s"); 23 | 24 | System.out.println("-----------------------"); 25 | System.out.println("Starting writing data..."); 26 | JsonFileSerializer serializer1 = (JsonFileSerializer) new FileSerializerBuilder().type(CompilationType.JSON).get(); 27 | serializer1.writeObject("int", 192); 28 | serializer1.writeObject("str", "test"); 29 | serializer1.writeObject("flt", 42.5f); 30 | serializer1.writeObject("ipt", InetAddress.getLocalHost()); 31 | long time1 = serializer1.compile(new File("data1")); 32 | serializer1.close(); 33 | System.out.println("Finished in "+(time1 / 1000)+"s"); 34 | 35 | System.out.println(HashUtils.sha1("Test")); 36 | 37 | CSVFileSerializer serializer2 = (CSVFileSerializer) new FileSerializerBuilder().type(CompilationType.CVS).get(); 38 | serializer2.setType(CSVFileSerializer.ColumnType.HORIZONTAL); 39 | serializer2.setDelemiter(";"); 40 | serializer2.addColumns("id", "value"); 41 | serializer2.setValue("id", "1"); 42 | serializer2.setValue("value", "123"); 43 | serializer2.addLine(); 44 | serializer2.setValue("id", "2"); 45 | serializer2.setValue("value", "456"); 46 | serializer2.compile(new File("file.csv")); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/HashTextSerializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.nio.charset.Charset; 4 | import java.security.MessageDigest; 5 | import java.security.NoSuchAlgorithmException; 6 | import java.util.UUID; 7 | 8 | /** 9 | * Created by Sofiane on 26/07/2017. 10 | * 11 | * @author Sofiane 12 | */ 13 | public class HashTextSerializer extends Serializer implements TextSerializer { 14 | 15 | private Hash hash; 16 | 17 | public HashTextSerializer(UUID identifier, Hash hash) { 18 | super(CompilationType.HASH, identifier); 19 | this.hash = hash; 20 | } 21 | 22 | public HashTextSerializer() { 23 | this(UUID.randomUUID(), Hash.SHA1); 24 | } 25 | 26 | @Override 27 | public String compile(byte[] data) { 28 | if(this.hash == null || data == null) throw new NullPointerException(); 29 | try { 30 | MessageDigest md = MessageDigest.getInstance(hash.f); 31 | byte[] b = md.digest(data); 32 | String result = ""; 33 | for (int i = 0; i < b.length; i++) { 34 | result += Integer.toString((b[i] & 0xff) + 0x100,16).substring(1); 35 | } 36 | return result.toUpperCase(); 37 | } catch (NoSuchAlgorithmException e) { 38 | e.printStackTrace(); 39 | } 40 | return null; 41 | } 42 | 43 | public String compile(String s, String encoding) { 44 | return this.compile(s.getBytes(Charset.forName(encoding))); 45 | } 46 | 47 | public String compile(String s) { 48 | return this.compile(s, "UTF-8"); 49 | } 50 | 51 | public boolean set(Hash hash) { 52 | if(this.hash == hash) return false; 53 | this.hash = hash; 54 | return true; 55 | } 56 | 57 | public Hash getHash() { 58 | return hash; 59 | } 60 | 61 | public enum Hash { 62 | SHA1("SHA-1"), 63 | SHA256("SHA-256"), 64 | MD5("MD5"); 65 | 66 | private final String f; 67 | 68 | Hash(String f){ 69 | this.f = f; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/FileInfo.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.*; 4 | import java.nio.file.Files; 5 | import java.util.Properties; 6 | 7 | /** 8 | * Created by Sofiane on 26/09/2017. 9 | * 10 | * @author Sofiane 11 | */ 12 | public class FileInfo { 13 | 14 | private File file; 15 | private Properties properties; 16 | 17 | public FileInfo(File file) { 18 | this.file = file; 19 | this.properties = new Properties(); 20 | try { 21 | this.properties.load(new FileInputStream(file)); 22 | } catch (IOException e) { 23 | e.printStackTrace(); 24 | } 25 | } 26 | 27 | public void put(String propertyName, String value){ 28 | this.properties.setProperty(propertyName, value); 29 | } 30 | 31 | public Properties getProperties() { 32 | return this.properties; 33 | } 34 | 35 | public void create() throws IOException { 36 | this.file.createNewFile(); 37 | } 38 | 39 | public byte[] readAllBytes() throws IOException { 40 | return Files.readAllBytes(file.toPath()); 41 | } 42 | 43 | public void save(String comments) { 44 | try { 45 | FileOutputStream out = new FileOutputStream(file); 46 | this.properties.store(out, comments); 47 | out.close(); 48 | } catch (IOException e) { 49 | e.printStackTrace(); 50 | } 51 | } 52 | 53 | public void rename(File newFile){ 54 | this.file.renameTo(newFile); 55 | } 56 | 57 | public void rename(String newName){ 58 | String[] array = this.file.getName().split("."); 59 | this.rename(new File(newName + (array[1] != null ? array[1] : ""))); 60 | } 61 | 62 | public void delete(){ 63 | this.file.delete(); 64 | } 65 | 66 | public File getFile() { 67 | return file; 68 | } 69 | 70 | @Override 71 | public int hashCode() { 72 | int result = file != null ? file.hashCode() : 0; 73 | result = 31 * result + (properties != null ? properties.hashCode() : 0); 74 | return result; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [download]: https://github.com/SofianeLeCubeur/DataSerializer/releases/latest 2 | [javadoc]: https://sofianelecubeur.github.io/DataSerializer/doc/ 3 | [version]: 0.0.3 4 | 5 |

DataSerializer

6 | 7 |

8 | Serialize and Deserialize data ! 9 | 10 | ## How to use an Serializer ? 11 | 12 | First, create A FileSerializerBuilder object and invoke "get" method to return the FileSerializer: 13 |
Example:
14 | ```java 15 | // Create first an builder with the compilation type and cast it 16 | JsonFileSerializer serializer = (JsonFileSerializer) new FileSerializerBuilder().type(CompilationType.JSON).get(); 17 | // write your data, Warning: the json serializer need keys ! 18 | serializer.writeObject("int", 192); 19 | serializer.writeObject("string", "test"); 20 | serializer.writeObject("float", 42.5f); 21 | // and for creating the file, juste call "compile" 22 | // method with the target file 23 | long execTime = serializer.compile(new File("data")); // You can get the time of the building task 24 | // Don't forget to close the serializer ! 25 | serializer.close(); 26 | ``` 27 |
28 | 29 | ## How to use an Deserializer ? 30 | 31 | First, create A FileDeserializerBuilder object and invoke "get" method to return the FileSerializer: 32 |
Example:
33 | ```java 34 | // Create first an builder with the compilation type and the file and cast it 35 | JsonFileDeserializer deserializer = (JsonFileDeserializer) new FileDeserializerBuilder().type(CompilationType.JSON).file(new File("data")).get(); 36 | // read your data, the Deserializer has DataInputStream as superclass, Warning: the json deserializer need keys ! 37 | int resultInt = deserializer.readInt("int"); 38 | String resultString = deserializer.readUTF("string"); 39 | float resultFloat = deserializer.readFloat("float"); 40 | // Don't forget to close the deserializer ! 41 | serializer.close(); 42 | ``` 43 |
44 | 45 | > **Tip**: You can use a "try-catch-with-ressources" instead calling close method. 46 | 47 | ## Installation 48 | 49 | Lastest Version: [download] 50 | 51 | Maven Integration 52 | 53 | Be sure to replace the **VERSION** key below with the latest version ! 54 | 55 | ```xml 56 | 57 | oss-sonatype 58 | oss-sonatype 59 | https://oss.sonatype.org/content/repositories/snapshots/ 60 | 61 | true 62 | 63 | 64 | 65 | 66 | com.github.sofianelecubeur 67 | DataSerializer 68 | VERSION 69 | 70 | ``` 71 | 72 | ## Documentation 73 | 74 | Find the JavaDoc here: [javadoc] 75 | 76 |

77 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/FileDeserializerBuilder.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.File; 4 | import java.util.UUID; 5 | 6 | /** 7 | * Created by SofianeLeCubeur on 24/06/2017. 8 | * 9 | * @author SofianeLeCubeur 10 | */ 11 | public class FileDeserializerBuilder { 12 | 13 | private CompilationType type; 14 | private File file; 15 | private CSVFileSerializer.ColumnType columnType; 16 | private String delimiter; 17 | private UUID identifier; 18 | 19 | public FileDeserializerBuilder() { 20 | this.type = CompilationType.BASE64; 21 | this.file = null; 22 | this.columnType = CSVFileSerializer.ColumnType.VERTICAL; 23 | this.identifier = UUID.randomUUID(); 24 | } 25 | 26 | /** 27 | * Set the deserializer type 28 | * @param type the deserializer type 29 | * @return this 30 | */ 31 | public FileDeserializerBuilder type(CompilationType type){ 32 | this.type = type; 33 | 34 | return this; 35 | } 36 | 37 | /** 38 | * Set the target file 39 | * @param file the target file 40 | * @return this 41 | */ 42 | public FileDeserializerBuilder file(File file){ 43 | this.file = file; 44 | 45 | return this; 46 | } 47 | 48 | /** 49 | * Set a custom identifier to the deserializer 50 | * @param identifier the custom identifier 51 | * @return this 52 | */ 53 | public FileDeserializerBuilder identifier(UUID identifier){ 54 | this.identifier = identifier; 55 | 56 | return this; 57 | } 58 | 59 | /** 60 | * Set the delimiter (Only used for CSV deserializer) 61 | * @param delimiter the delimiter 62 | * @return this 63 | */ 64 | public FileDeserializerBuilder delemiter(String delimiter){ 65 | this.delimiter = delimiter; 66 | 67 | return this; 68 | } 69 | 70 | /** 71 | * Set the column Type (Only used for CSV deserializer) 72 | * @param columnType the column type 73 | * @return this 74 | */ 75 | public FileDeserializerBuilder type2(CSVFileSerializer.ColumnType columnType){ 76 | this.columnType = columnType; 77 | 78 | return this; 79 | } 80 | 81 | /** 82 | * Build the Deserializer 83 | * @return Deserializer 84 | */ 85 | public Deserializer get(){ 86 | try { 87 | switch (this.type) { 88 | case JSON: 89 | return new JsonFileDeserializer(this.file, this.identifier); 90 | case BINARY: 91 | return new BinaryFileDeserializer(this.file, this.identifier); 92 | case BASE64: 93 | return new Base64FileDeserializer(this.file, this.identifier); 94 | case CVS: 95 | return (delimiter != null ? new CSVFileDeserializer(this.file, columnType, delimiter, this.identifier) 96 | : new CSVFileDeserializer(this.file, this.identifier)); 97 | } 98 | } catch (Exception e) { 99 | e.printStackTrace(); 100 | } 101 | return null; 102 | } 103 | 104 | } -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/JsonFileDeserializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.IOException; 7 | import java.io.ObjectInputStream; 8 | import java.util.UUID; 9 | 10 | import org.json.simple.JSONObject; 11 | import org.json.simple.parser.JSONParser; 12 | import org.json.simple.parser.ParseException; 13 | 14 | /** 15 | * Created by SofianeLeCubeur on 24/06/2017. 16 | * 17 | * @author SofianeLeCubeur 18 | * 19 | * lease use internal read methods with keys ! 20 | */ 21 | public class JsonFileDeserializer extends Deserializer { 22 | 23 | private File file; 24 | private JSONObject json; 25 | 26 | public JsonFileDeserializer(File file, UUID identifier) throws ParseException, IOException { 27 | this(new FileInputStream(file), identifier); 28 | this.file = file; 29 | } 30 | 31 | public JsonFileDeserializer(FileInputStream in, UUID identifier) throws ParseException, IOException { 32 | super(CompilationType.JSON, in, identifier); 33 | this.createJSONObject(in); 34 | } 35 | 36 | private void createJSONObject(FileInputStream in) throws ParseException, IOException { 37 | DataInputStream stream = new DataInputStream(in); 38 | JSONParser parser = new JSONParser(); 39 | this.json = (JSONObject) parser.parse(stream.readUTF()); 40 | stream.close(); 41 | } 42 | 43 | @SuppressWarnings("unchecked") 44 | public T readObject(Class clazz) throws IOException, ClassNotFoundException { 45 | ObjectInputStream in = new ObjectInputStream(this.in); 46 | Object o = in.readObject(); 47 | if(!clazz.isInstance(o)) 48 | return null; 49 | return (T) o; 50 | } 51 | 52 | public Object readObject() throws IOException, ClassNotFoundException { 53 | ObjectInputStream in = new ObjectInputStream(this.in); 54 | return in.readObject(); 55 | } 56 | 57 | public FileInfo info(){ 58 | if(this.file == null) throw new NullPointerException(); 59 | return new FileInfo(this.file); 60 | } 61 | 62 | public Integer readInt(String key){ 63 | return Integer.valueOf((String) this.json.get(key)); 64 | } 65 | 66 | public Short readShort(String key){ 67 | return Short.valueOf((String) this.json.get(key)); 68 | } 69 | 70 | public Long readLong(Long key){ 71 | return Long.valueOf((String) this.json.get(key)); 72 | } 73 | 74 | public Float readFloat(String key){ 75 | return Float.valueOf((String) this.json.get(key)); 76 | } 77 | 78 | public Double readDouble(String key){ 79 | return Double.valueOf((String) this.json.get(key)); 80 | } 81 | 82 | public Boolean readBoolean(String key){ 83 | return Boolean.valueOf((String) this.json.get(key)); 84 | } 85 | 86 | public String readUTF(String key){ 87 | return (String) this.json.get(key); 88 | } 89 | 90 | public Object readObject(String key){ 91 | return (String) this.json.get(key); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/base64/ExportPriv.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer.base64; 2 | 3 | // How to export the private key from keystore? 4 | // Does keytool not have an option to do so? 5 | // This example use the "testkeys" file that comes with JSSE 1.0.3 6 | // Alexey Zilber: Ported to work with Base64Coder: http://www.source-code.biz/snippets/java/2.htm 7 | 8 | 9 | import java.security.cert.Certificate; 10 | import java.security.*; 11 | import java.io.File; 12 | import java.io.FileInputStream; 13 | 14 | class ExportPriv { 15 | public static void main(String args[]) throws Exception { 16 | if (args.length < 2) { 17 | //Yes I know this sucks (the password is visible to other users via ps 18 | // but this was a quick-n-dirty fix to export from a keystore to pkcs12 19 | // someday I may fix, but for now it'll have to do. 20 | System.err.println("Usage: java ExportPriv "); 21 | System.exit(1); 22 | } 23 | ExportPriv myep = new ExportPriv(); 24 | myep.doit(args[0], args[1], args[2]); 25 | } 26 | 27 | public void doit(String fileName, String aliasName, String pass) throws Exception { 28 | 29 | KeyStore ks = KeyStore.getInstance("JKS"); 30 | 31 | char[] passPhrase = pass.toCharArray(); 32 | //BASE64Encoder myB64 = new BASE64Encoder(); 33 | 34 | File certificateFile = new File(fileName); 35 | ks.load(new FileInputStream(certificateFile), passPhrase); 36 | 37 | KeyPair kp = getPrivateKey(ks, aliasName, passPhrase); 38 | 39 | PrivateKey privKey = kp.getPrivate(); 40 | 41 | char[] b64 = Base64Coder.encode(privKey.getEncoded()); 42 | 43 | System.out.println("-----BEGIN PRIVATE KEY-----"); 44 | System.out.println(b64); 45 | System.out.println("-----END PRIVATE KEY-----"); 46 | 47 | } 48 | 49 | // From http://javaalmanac.com/egs/java.security/GetKeyFromKs.html 50 | 51 | public KeyPair getPrivateKey(KeyStore keystore, String alias, char[] password) { 52 | try { 53 | // Get private key 54 | Key key = keystore.getKey(alias, password); 55 | 56 | System.out.println(key); 57 | 58 | if (key instanceof PrivateKey) { 59 | // Get certificate of public key 60 | Certificate cert = keystore.getCertificate(alias); 61 | 62 | // Get public key 63 | PublicKey publicKey = cert.getPublicKey(); 64 | 65 | // Return a key pair 66 | return new KeyPair(publicKey, (PrivateKey) key); 67 | } 68 | } catch (UnrecoverableKeyException e) { 69 | e.printStackTrace(); 70 | } catch (NoSuchAlgorithmException e) { 71 | e.printStackTrace(); 72 | } catch (KeyStoreException e) { 73 | e.printStackTrace(); 74 | } 75 | return null; 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/Base64FileDeserializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.DataInputStream; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.IOException; 8 | import java.io.ObjectInputStream; 9 | import java.util.UUID; 10 | 11 | import fr.sofianelecubeur.dataserializer.base64.Base64Coder; 12 | 13 | /** 14 | * Created by SofianeLeCubeur on 24/06/2017. 15 | * 16 | * @author SofianeLeCubeur 17 | */ 18 | public class Base64FileDeserializer extends Deserializer { 19 | 20 | private File file; 21 | 22 | public Base64FileDeserializer(File file, UUID identifier) throws IOException { 23 | this(new FileInputStream(file), identifier); 24 | this.file = file; 25 | } 26 | 27 | public Base64FileDeserializer(FileInputStream in, UUID identifier) throws IOException { 28 | super(CompilationType.BINARY, createBase64Stream(in), identifier); 29 | } 30 | 31 | public Base64FileDeserializer(FileInputStream in, boolean compression, UUID identifier) throws IOException { 32 | super(CompilationType.BINARY, (compression ? createBase64StreamWithCompression(in) : createBase64Stream(in)), identifier); 33 | } 34 | 35 | /** 36 | * Read a specified Object 37 | * @param clazz the return object type 38 | * @param the object (null if not the same type) 39 | * @return The Object 40 | * @throws IOException exceptions from {@link ObjectInputStream} 41 | * @throws ClassNotFoundException if the class is not found 42 | */ 43 | @SuppressWarnings("unchecked") 44 | public T readObject(Class clazz) throws IOException, ClassNotFoundException { 45 | ObjectInputStream in = new ObjectInputStream(this.in); 46 | Object o = in.readObject(); 47 | if(!clazz.isInstance(o)) 48 | return null; 49 | return (T) o; 50 | } 51 | 52 | public Object readObject() throws IOException, ClassNotFoundException { 53 | ObjectInputStream in = new ObjectInputStream(this.in); 54 | return in.readObject(); 55 | } 56 | 57 | /** 58 | * Get File informations 59 | * @return the {@link FileInfo} object 60 | */ 61 | public FileInfo info(){ 62 | if(this.file == null) throw new NullPointerException(); 63 | return new FileInfo(this.file); 64 | } 65 | 66 | protected static DataInputStream createBase64Stream(FileInputStream in) throws IOException { 67 | DataInputStream bytes = new DataInputStream(in); 68 | 69 | byte[] bf = Base64Coder.decodeLines(bytes.readUTF()); 70 | ByteArrayInputStream stream = new ByteArrayInputStream(bf); 71 | 72 | in.close(); 73 | bytes.close(); 74 | return new DataInputStream(stream); 75 | } 76 | 77 | protected static DataInputStream createBase64StreamWithCompression(FileInputStream in) throws IOException { 78 | DataInputStream bytes = new DataInputStream(in); 79 | 80 | byte[] bf = Base64Coder.decodeLines(bytes.readUTF()); 81 | byte[] data = CompressionUtils.decompress(bf); 82 | ByteArrayInputStream stream = new ByteArrayInputStream(data); 83 | 84 | in.close(); 85 | bytes.close(); 86 | return new DataInputStream(stream); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Generated Documentation (Untitled) 7 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | <noscript> 68 | <div>JavaScript is disabled on your browser.</div> 69 | </noscript> 70 | <h2>Frame Alert</h2> 71 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="overview-summary.html">Non-frame version</a>.</p> 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/BinaryFileSerializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.BufferedOutputStream; 5 | import java.io.ByteArrayInputStream; 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.DataOutputStream; 8 | import java.io.File; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | import java.io.ObjectOutputStream; 12 | import java.util.UUID; 13 | 14 | /** 15 | * Created by SofianeLeCubeur on 24/06/2017. 16 | * 17 | * @author SofianeLeCubeur 18 | */ 19 | public class BinaryFileSerializer extends Serializer implements FileSerializer { 20 | 21 | private ByteArrayOutputStream bytes; 22 | private DataOutputStream outStream; 23 | private final int byteArrayLength; 24 | 25 | public BinaryFileSerializer(int byteArrayLength, UUID identifier) { 26 | super(CompilationType.BINARY, identifier); 27 | this.byteArrayLength = byteArrayLength; 28 | this.bytes = new ByteArrayOutputStream(); 29 | this.outStream = new DataOutputStream(bytes); 30 | } 31 | 32 | @Override 33 | public void write(byte[] o) throws IOException { 34 | this.outStream.write(o); 35 | } 36 | 37 | @Override 38 | public void writeInt(Integer o) throws IOException { 39 | this.outStream.writeInt(o); 40 | } 41 | 42 | @Override 43 | public void writeShort(Short o) throws IOException { 44 | this.outStream.writeShort(o); 45 | } 46 | 47 | @Override 48 | public void writeLong(Long o) throws IOException { 49 | this.outStream.writeLong(o); 50 | } 51 | 52 | @Override 53 | public void writeDouble(Double o) throws IOException { 54 | this.outStream.writeDouble(o); 55 | } 56 | 57 | @Override 58 | public void writeFloat(Float o) throws IOException { 59 | this.outStream.writeFloat(o); 60 | } 61 | 62 | @Override 63 | public void writeBoolean(Boolean o) throws IOException { 64 | this.outStream.writeBoolean(o); 65 | } 66 | 67 | @Override 68 | public void writeUTF(String o) throws IOException { 69 | this.outStream.writeUTF(o); 70 | } 71 | 72 | @Override 73 | public void writeObject(Object o) throws IOException { 74 | ObjectOutputStream oos = new ObjectOutputStream(bytes); 75 | oos.writeObject(o); 76 | oos.close(); 77 | } 78 | 79 | @Override 80 | public long compile(File file) throws IOException { 81 | long sT = System.currentTimeMillis(); 82 | 83 | BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(bytes.toByteArray())); 84 | BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file)); 85 | byte[] bf = new byte[this.byteArrayLength]; 86 | 87 | while(in.read(bf) != -1){ 88 | out.write(bf); 89 | } 90 | 91 | out.close(); 92 | in.close(); 93 | 94 | return (System.currentTimeMillis() - sT); 95 | } 96 | 97 | @Override 98 | public void close() throws IOException { 99 | this.bytes.close(); 100 | this.outStream.close(); 101 | super.close(); 102 | } 103 | 104 | public void compress(int level) throws IOException { 105 | byte[] old = bytes.toByteArray(); 106 | byte[] compressed = CompressionUtils.compress(old, level); 107 | bytes = new ByteArrayOutputStream(); 108 | bytes.write(compressed); 109 | } 110 | 111 | public ByteArrayOutputStream getBytes() { 112 | return bytes; 113 | } 114 | 115 | public DataOutputStream getStream() { 116 | return outStream; 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/Base64FileSerializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.BufferedOutputStream; 5 | import java.io.ByteArrayInputStream; 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.DataOutputStream; 8 | import java.io.File; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | import java.io.ObjectOutputStream; 12 | import java.util.UUID; 13 | 14 | import fr.sofianelecubeur.dataserializer.base64.Base64Coder; 15 | 16 | /** 17 | * Created by SofianeLeCubeur on 24/06/2017. 18 | * 19 | * @author SofianeLeCubeur 20 | */ 21 | public class Base64FileSerializer extends Serializer implements FileSerializer { 22 | 23 | private ByteArrayOutputStream bytes; 24 | private DataOutputStream outStream; 25 | private final int byteArrayLength; 26 | 27 | public Base64FileSerializer(int byteArrayLength, UUID identifier) { 28 | super(CompilationType.BASE64, identifier); 29 | this.byteArrayLength = byteArrayLength; 30 | this.bytes = new ByteArrayOutputStream(); 31 | this.outStream = new DataOutputStream(bytes); 32 | } 33 | 34 | @Override 35 | public void write(byte[] o) throws IOException { 36 | this.outStream.write(o); 37 | } 38 | 39 | @Override 40 | public void writeInt(Integer o) throws IOException { 41 | this.outStream.writeInt(o); 42 | } 43 | 44 | @Override 45 | public void writeShort(Short o) throws IOException { 46 | this.outStream.writeShort(o); 47 | } 48 | 49 | @Override 50 | public void writeLong(Long o) throws IOException { 51 | this.outStream.writeLong(o); 52 | } 53 | 54 | @Override 55 | public void writeDouble(Double o) throws IOException { 56 | this.outStream.writeDouble(o); 57 | } 58 | 59 | @Override 60 | public void writeFloat(Float o) throws IOException { 61 | this.outStream.writeFloat(o); 62 | } 63 | 64 | @Override 65 | public void writeBoolean(Boolean o) throws IOException { 66 | this.outStream.writeBoolean(o); 67 | } 68 | 69 | @Override 70 | public void writeUTF(String o) throws IOException { 71 | this.outStream.writeUTF(o); 72 | } 73 | 74 | @Override 75 | public void writeObject(Object o) throws IOException { 76 | ObjectOutputStream oos = new ObjectOutputStream(bytes); 77 | oos.writeObject(o); 78 | oos.close(); 79 | } 80 | 81 | @Override 82 | public long compile(File file) throws IOException { 83 | long sT = System.currentTimeMillis(); 84 | 85 | ByteArrayOutputStream o = new ByteArrayOutputStream(); 86 | DataOutputStream o1 = new DataOutputStream(o); 87 | o1.writeUTF(Base64Coder.encodeLines(bytes.toByteArray())); 88 | o1.close(); 89 | 90 | BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(o.toByteArray())); 91 | BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file)); 92 | byte[] bf = new byte[this.byteArrayLength]; 93 | 94 | while(in.read(bf) != -1){ 95 | out.write(bf); 96 | } 97 | 98 | o.close(); 99 | in.close(); 100 | out.close(); 101 | 102 | return (System.currentTimeMillis() - sT); 103 | } 104 | 105 | @Override 106 | public void close() throws IOException { 107 | this.bytes.close(); 108 | this.outStream.close(); 109 | super.close(); 110 | } 111 | 112 | public void compress(int level) throws IOException { 113 | byte[] old = bytes.toByteArray(); 114 | byte[] compressed = CompressionUtils.compress(old, level); 115 | bytes = new ByteArrayOutputStream(); 116 | bytes.write(compressed); 117 | } 118 | 119 | public ByteArrayOutputStream getBytes() { 120 | return this.bytes; 121 | } 122 | 123 | public DataOutputStream getStream() { 124 | return this.outStream; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /doc/fr/sofianelecubeur/dataserializer/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | fr.sofianelecubeur.dataserializer 7 | 8 | 9 | 10 | 11 | 12 |

fr.sofianelecubeur.dataserializer

13 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/JsonFileSerializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.BufferedOutputStream; 5 | import java.io.ByteArrayInputStream; 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.DataOutputStream; 8 | import java.io.File; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | import java.util.Collection; 12 | import java.util.UUID; 13 | 14 | import org.json.simple.JSONArray; 15 | import org.json.simple.JSONObject; 16 | 17 | /** 18 | * Created by SofianeLeCubeur on 24/06/2017. 19 | * 20 | * @author SofianeLeCubeur 21 | */ 22 | @SuppressWarnings("unchecked") 23 | public class JsonFileSerializer extends Serializer implements FileSerializer { 24 | 25 | private JSONObject json; 26 | private final int byteArrayLength; 27 | 28 | public JsonFileSerializer(int byteArrayLength, UUID identifier) { 29 | super(CompilationType.JSON, identifier); 30 | this.json = new JSONObject(); 31 | this.byteArrayLength = byteArrayLength; 32 | } 33 | 34 | @Deprecated 35 | @Override 36 | public void write(byte[] o) throws IOException { 37 | throw new UnsupportedOperationException(); 38 | } 39 | 40 | @Deprecated 41 | @Override 42 | public void writeInt(Integer o) throws IOException { 43 | throw new UnsupportedOperationException(); 44 | } 45 | 46 | @Deprecated 47 | @Override 48 | public void writeShort(Short o) throws IOException { 49 | throw new UnsupportedOperationException(); 50 | } 51 | 52 | @Deprecated 53 | @Override 54 | public void writeLong(Long o) throws IOException { 55 | throw new UnsupportedOperationException(); 56 | } 57 | 58 | @Deprecated 59 | @Override 60 | public void writeDouble(Double o) throws IOException { 61 | throw new UnsupportedOperationException(); 62 | } 63 | 64 | @Deprecated 65 | @Override 66 | public void writeFloat(Float o) throws IOException { 67 | throw new UnsupportedOperationException(); 68 | } 69 | 70 | @Deprecated 71 | @Override 72 | public void writeBoolean(Boolean o) throws IOException { 73 | throw new UnsupportedOperationException(); 74 | } 75 | 76 | @Deprecated 77 | @Override 78 | public void writeUTF(String o) throws IOException { 79 | throw new UnsupportedOperationException(); 80 | } 81 | 82 | @Deprecated 83 | @Override 84 | public void writeObject(Object o) throws IOException { 85 | throw new UnsupportedOperationException(); 86 | } 87 | 88 | public void writeObject(String key, Object value){ 89 | this.json.put(key, value.toString()); 90 | } 91 | 92 | public void writeArray(String key, Object[] value){ 93 | if (!json.containsKey(key)) { 94 | json.put(key, new JSONArray()); 95 | } 96 | JSONArray array = (JSONArray) json.get(key); 97 | for (int i = 0; i < value.length; i++) 98 | array.add(value[i]); 99 | json.put(key, array); 100 | } 101 | 102 | public void writeArray(String key, Collection value){ 103 | if (!json.containsKey(key)) { 104 | json.put(key, new JSONArray()); 105 | } 106 | JSONArray array = (JSONArray) json.get(key); 107 | array.addAll(value); 108 | json.put(key, array); 109 | } 110 | 111 | @Override 112 | public long compile(File file) throws IOException { 113 | long sT = System.currentTimeMillis(); 114 | 115 | ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 116 | DataOutputStream outStream = new DataOutputStream(bytes); 117 | outStream.writeUTF(this.json.toJSONString()); 118 | 119 | BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(bytes.toByteArray())); 120 | BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file)); 121 | byte[] bf = new byte[this.byteArrayLength]; 122 | 123 | while(in.read(bf) != -1){ 124 | out.write(bf); 125 | } 126 | 127 | out.close(); 128 | in.close(); 129 | 130 | return (System.currentTimeMillis() - sT); 131 | } 132 | 133 | @Override 134 | public void close() throws IOException { 135 | json.clear(); 136 | super.close(); 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /doc/constant-values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Constant Field Values 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Constant Field Values

73 |

Contents

74 |
75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 92 |
93 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /doc/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /doc/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /doc/overview-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Overview 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 |
Packages 
PackageDescription
fr.sofianelecubeur.dataserializer 
fr.sofianelecubeur.dataserializer.base64 
fr.sofianelecubeur.dataserializer.util 
93 |
94 | 95 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 111 |
112 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/CSVFileDeserializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.*; 4 | import java.nio.file.Files; 5 | import java.nio.file.Paths; 6 | import java.util.*; 7 | 8 | /** 9 | * Created by Sofiane on 17/10/2017. 10 | * 11 | * @author Sofiane 12 | */ 13 | public class CSVFileDeserializer extends Deserializer { 14 | 15 | private File file; 16 | private String delemiter = ","; 17 | private CSVFileSerializer.ColumnType columnType; 18 | private Set columns; 19 | private int rows; 20 | private Map> values; 21 | 22 | public CSVFileDeserializer(File file, UUID identifier) throws IOException { 23 | this(new FileInputStream(file), identifier); 24 | this.file = file; 25 | this.columnType = CSVFileSerializer.ColumnType.VERTICAL; 26 | this.loadValues(file); 27 | } 28 | 29 | public CSVFileDeserializer(File file, String delimiter, UUID identifier) throws IOException { 30 | this(file, CSVFileSerializer.ColumnType.VERTICAL, delimiter, identifier); 31 | } 32 | 33 | public CSVFileDeserializer(File file, CSVFileSerializer.ColumnType columnType, String delimiter, UUID identifier) throws IOException { 34 | this(new FileInputStream(file), identifier); 35 | this.file = file; 36 | this.columnType = columnType; 37 | this.delemiter = delimiter; 38 | this.loadValues(file); 39 | } 40 | 41 | private CSVFileDeserializer(FileInputStream in, UUID identifier) throws IOException { 42 | super(CompilationType.CVS, in, identifier); 43 | } 44 | 45 | protected void loadValues(File file) throws IOException { 46 | this.columns = new HashSet<>(); 47 | this.values = new HashMap<>(); 48 | List lines = Files.readAllLines(Paths.get(file.toURI())); 49 | if(lines.isEmpty()) throw new IllegalStateException("Invalid CSV file."); 50 | if(columnType == CSVFileSerializer.ColumnType.VERTICAL) { 51 | String line = lines.stream().findFirst().get(); 52 | for (String col : line.split(delemiter)) 53 | columns.add(col); 54 | 55 | Map indexMap = new HashMap<>(); 56 | int index = 0; 57 | for (String column : columns) 58 | indexMap.put(index++, column); 59 | rows = (lines.size() - 1); 60 | 61 | Map values; 62 | int cur; 63 | for (int i = 1; i < (rows + 1); i++) { 64 | line = lines.get(i); 65 | values = new HashMap<>(); 66 | cur = 0; 67 | for (String val : line.split(delemiter)) { 68 | values.put(indexMap.get(cur++), val); 69 | } 70 | this.values.put((i - 1), values); 71 | } 72 | }else { 73 | int cur = 0; 74 | for (String line : lines){ 75 | String[] content = line.split(delemiter); 76 | String column = content[0]; 77 | columns.add(column); 78 | for (int i = 1; i < content.length; i++) { 79 | values.put(cur++, Collections.singletonMap(column, content[i])); 80 | } 81 | } 82 | rows = cur; 83 | } 84 | } 85 | 86 | public Set getColumns() { 87 | return columns; 88 | } 89 | 90 | public String getColumnsString() { 91 | StringJoiner joiner = new StringJoiner(", "); 92 | columns.forEach(col -> joiner.add(col)); 93 | return joiner.toString(); 94 | } 95 | 96 | /** 97 | * Get the delimiter 98 | * @return the delimiter 99 | */ 100 | public String getDelemiter() { 101 | return delemiter; 102 | } 103 | 104 | /** 105 | * Get total rows 106 | * @return total rows 107 | */ 108 | public int getRows() { 109 | return rows; 110 | } 111 | 112 | public String getValue(int line, String column) { 113 | return values.get(line).get(column); 114 | } 115 | 116 | public Collection getValues(String column) { 117 | List list = new ArrayList<>(); 118 | for (int i = 0; i < values.size(); i++) { 119 | Map map = values.get(i); 120 | if(map.containsKey(column)) 121 | for (Map.Entry entry : map.entrySet()){ 122 | if(entry.getKey().equalsIgnoreCase(column)) 123 | list.add(entry.getValue()); 124 | } 125 | } 126 | return list; 127 | } 128 | 129 | /** 130 | * Get all values for a line 131 | * @param line the target line 132 | * @return alls values for the line 133 | */ 134 | public Collection getValues(int line) { 135 | return values.get(line).values(); 136 | } 137 | 138 | /** 139 | * Get all values in a string 140 | * @return All values formated 141 | */ 142 | public String getValuesString(){ 143 | StringJoiner joiner = new StringJoiner(", "); 144 | for (int i = 0; i < rows; i++) 145 | getValues(i).forEach(val -> joiner.add(val)); 146 | return joiner.toString(); 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /doc/fr/sofianelecubeur/dataserializer/base64/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | fr.sofianelecubeur.dataserializer.base64 Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package fr.sofianelecubeur.dataserializer.base64

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 |
    81 |
  • java.lang.Object 82 |
      83 |
    • fr.sofianelecubeur.dataserializer.base64.Base64Coder
    • 84 |
    85 |
  • 86 |
87 |
88 | 89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 105 |
106 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /doc/fr/sofianelecubeur/dataserializer/util/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | fr.sofianelecubeur.dataserializer.util Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package fr.sofianelecubeur.dataserializer.util

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 |
    81 |
  • java.lang.Object 82 |
      83 |
    • fr.sofianelecubeur.dataserializer.util.HashUtils
    • 84 |
    • fr.sofianelecubeur.dataserializer.util.Pair<L,R>
    • 85 |
    86 |
  • 87 |
88 |
89 | 90 |
91 | 92 | 93 | 94 | 95 | 96 | 97 | 106 |
107 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /doc/fr/sofianelecubeur/dataserializer/base64/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | fr.sofianelecubeur.dataserializer.base64 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Package fr.sofianelecubeur.dataserializer.base64

73 |
74 |
75 |
    76 |
  • 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 89 | 90 | 91 |
    Class Summary 
    ClassDescription
    Base64Coder 87 |
    A Base64 encoder/decoder.
    88 |
    92 |
  • 93 |
94 |
95 | 96 |
97 | 98 | 99 | 100 | 101 | 102 | 103 | 112 |
113 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /doc/fr/sofianelecubeur/dataserializer/util/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | fr.sofianelecubeur.dataserializer.util 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Package fr.sofianelecubeur.dataserializer.util

73 |
74 |
75 |
    76 |
  • 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 89 | 90 | 91 | 92 | 95 | 96 | 97 |
    Class Summary 
    ClassDescription
    HashUtils 87 |
    Created by Sofiane on 26/09/2017.
    88 |
    Pair<L,R> 93 |
    Created by Sofiane on 09/11/2017.
    94 |
    98 |
  • 99 |
100 |
101 | 102 |
103 | 104 | 105 | 106 | 107 | 108 | 109 | 118 |
119 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /doc/index-files/index-11.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | L-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
A B C D E F G H I J L M P R S T V W  72 | 73 | 74 |

L

75 |
76 |
length(int) - Method in class fr.sofianelecubeur.dataserializer.FileSerializerBuilder
77 |
78 |
Use a custom buffer length
79 |
80 |
81 | A B C D E F G H I J L M P R S T V W 
82 | 83 |
84 | 85 | 86 | 87 | 88 | 89 | 90 | 99 |
100 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /doc/index-files/index-12.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | M-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
A B C D E F G H I J L M P R S T V W  72 | 73 | 74 |

M

75 |
76 |
md5(byte[]) - Static method in class fr.sofianelecubeur.dataserializer.util.HashUtils
77 |
 
78 |
md5(String) - Static method in class fr.sofianelecubeur.dataserializer.util.HashUtils
79 |
 
80 |
81 | A B C D E F G H I J L M P R S T V W 
82 | 83 |
84 | 85 | 86 | 87 | 88 | 89 | 90 | 99 |
100 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /doc/index-files/index-1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | A-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
A B C D E F G H I J L M P R S T V W  72 | 73 | 74 |

A

75 |
76 |
addColumn(String) - Method in class fr.sofianelecubeur.dataserializer.CSVFileSerializer
77 |
78 |
Add a column
79 |
80 |
addColumns(String...) - Method in class fr.sofianelecubeur.dataserializer.CSVFileSerializer
81 |
82 |
Add multiples columns
83 |
84 |
addLine() - Method in class fr.sofianelecubeur.dataserializer.CSVFileSerializer
85 |
86 |
Add a line (only when the columnType is Vertical)
87 |
88 |
89 | A B C D E F G H I J L M P R S T V W 
90 | 91 |
92 | 93 | 94 | 95 | 96 | 97 | 98 | 107 |
108 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /doc/index-files/index-13.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | P-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
A B C D E F G H I J L M P R S T V W  72 | 73 | 74 |

P

75 |
76 |
Pair<L,R> - Class in fr.sofianelecubeur.dataserializer.util
77 |
78 |
Created by Sofiane on 09/11/2017.
79 |
80 |
Pair(L, R) - Constructor for class fr.sofianelecubeur.dataserializer.util.Pair
81 |
 
82 |
put(String, String) - Method in class fr.sofianelecubeur.dataserializer.FileInfo
83 |
 
84 |
85 | A B C D E F G H I J L M P R S T V W 
86 | 87 |
88 | 89 | 90 | 91 | 92 | 93 | 94 | 103 |
104 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /doc/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Deprecated List 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Deprecated API

73 |

Contents

74 | 77 |
78 | 121 | 122 |
123 | 124 | 125 | 126 | 127 | 128 | 129 | 138 |
139 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /doc/index-files/index-9.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | I-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
A B C D E F G H I J L M P R S T V W  72 | 73 | 74 |

I

75 |
76 |
identifier(UUID) - Method in class fr.sofianelecubeur.dataserializer.FileDeserializerBuilder
77 |
78 |
Set a custom identifier to the deserializer
79 |
80 |
identifier(UUID) - Method in class fr.sofianelecubeur.dataserializer.FileSerializerBuilder
81 |
82 |
Set a custom identifier
83 |
84 |
info() - Method in class fr.sofianelecubeur.dataserializer.Base64FileDeserializer
85 |
86 |
Get File informations
87 |
88 |
info() - Method in class fr.sofianelecubeur.dataserializer.BinaryFileDeserializer
89 |
 
90 |
info() - Method in class fr.sofianelecubeur.dataserializer.JsonFileDeserializer
91 |
 
92 |
93 | A B C D E F G H I J L M P R S T V W 
94 | 95 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 111 |
112 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /doc/index-files/index-10.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | J-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
A B C D E F G H I J L M P R S T V W  72 | 73 | 74 |

J

75 |
76 |
JsonFileDeserializer - Class in fr.sofianelecubeur.dataserializer
77 |
78 |
Created by SofianeLeCubeur on 24/06/2017.
79 |
80 |
JsonFileDeserializer(File, UUID) - Constructor for class fr.sofianelecubeur.dataserializer.JsonFileDeserializer
81 |
 
82 |
JsonFileDeserializer(FileInputStream, UUID) - Constructor for class fr.sofianelecubeur.dataserializer.JsonFileDeserializer
83 |
 
84 |
JsonFileSerializer - Class in fr.sofianelecubeur.dataserializer
85 |
86 |
Created by SofianeLeCubeur on 24/06/2017.
87 |
88 |
JsonFileSerializer(int, UUID) - Constructor for class fr.sofianelecubeur.dataserializer.JsonFileSerializer
89 |
 
90 |
91 | A B C D E F G H I J L M P R S T V W 
92 | 93 |
94 | 95 | 96 | 97 | 98 | 99 | 100 | 109 |
110 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /src/main/java/fr/sofianelecubeur/dataserializer/CSVFileSerializer.java: -------------------------------------------------------------------------------- 1 | package fr.sofianelecubeur.dataserializer; 2 | 3 | import java.io.*; 4 | import java.util.*; 5 | import java.util.function.Function; 6 | 7 | /** 8 | * Created by Sofiane on 14/10/2017. 9 | * 10 | * @author Sofiane 11 | */ 12 | public class CSVFileSerializer extends Serializer implements FileSerializer { 13 | 14 | private Map> values; 15 | private Set columns; 16 | private String delemiter = ","; 17 | private ColumnType type; 18 | private int lines = 1; 19 | 20 | public CSVFileSerializer(UUID uuid) { 21 | super(CompilationType.CVS, uuid); 22 | this.values = new HashMap<>(); 23 | this.columns = new HashSet<>(); 24 | this.type = ColumnType.VERTICAL; 25 | } 26 | 27 | public void setType(ColumnType type) { 28 | this.type = type; 29 | } 30 | 31 | /** 32 | * Set the value delmiter, in exel, the demlimiter is "," 33 | * @param delemiter the delimiter 34 | */ 35 | public void setDelemiter(String delemiter) { 36 | if(delemiter == null) throw new NullPointerException(); 37 | this.delemiter = delemiter; 38 | } 39 | 40 | /** 41 | * Add a column 42 | * @param column the column to add 43 | * @return if the column was added 44 | */ 45 | public boolean addColumn(String column){ 46 | if(column == null) throw new NullPointerException(); 47 | if(columns.contains(column)) return false; 48 | columns.add(column); 49 | return true; 50 | } 51 | 52 | /** 53 | * Add multiples columns 54 | * @param columns alls columns to add 55 | */ 56 | public void addColumns(String... columns){ 57 | if(columns == null) throw new NullPointerException(); 58 | for (String column : columns){ 59 | if(!this.columns.contains(column)) this.columns.add(column); 60 | } 61 | } 62 | 63 | /** 64 | * Remove a column 65 | * @param column the target column 66 | * @return if the column was removed 67 | */ 68 | public boolean removeColumn(String column){ 69 | if(column == null) throw new NullPointerException(); 70 | if(!columns.contains(column)) return false; 71 | columns.remove(column); 72 | return true; 73 | } 74 | 75 | /** 76 | * Get all columns 77 | * @return all columns 78 | */ 79 | public Set getColumns() { 80 | return columns; 81 | } 82 | 83 | @Override 84 | public void write(byte[] o) throws IOException { 85 | throw new UnsupportedOperationException(); 86 | } 87 | 88 | @Override 89 | public void writeInt(Integer o) throws IOException { 90 | throw new UnsupportedOperationException(); 91 | } 92 | 93 | @Override 94 | public void writeShort(Short o) throws IOException { 95 | throw new UnsupportedOperationException(); 96 | } 97 | 98 | @Override 99 | public void writeLong(Long o) throws IOException { 100 | throw new UnsupportedOperationException(); 101 | } 102 | 103 | @Override 104 | public void writeDouble(Double o) throws IOException { 105 | throw new UnsupportedOperationException(); 106 | } 107 | 108 | @Override 109 | public void writeFloat(Float o) throws IOException { 110 | throw new UnsupportedOperationException(); 111 | } 112 | 113 | @Override 114 | public void writeBoolean(Boolean o) throws IOException { 115 | throw new UnsupportedOperationException(); 116 | } 117 | 118 | @Override 119 | public void writeUTF(String o) throws IOException { 120 | throw new UnsupportedOperationException(); 121 | } 122 | 123 | @Override 124 | public void writeObject(Object o) throws IOException { 125 | throw new UnsupportedOperationException(); 126 | } 127 | 128 | /** 129 | * Set a value 130 | * @param column the target column 131 | * @param value the value 132 | */ 133 | public void setValue(String column, String value){ 134 | if(column == null || value == null) throw new NullPointerException(); 135 | if(!this.columns.contains(column)) throw new RuntimeException("Unknown column '"+column+"'"); 136 | Map map = this.values.get(lines); 137 | if(map == null){ 138 | map = new HashMap<>(); 139 | this.values.put(lines, map); 140 | } 141 | map.put(column, format(value)); 142 | } 143 | 144 | /** 145 | * Set a value 146 | * @param column the target column 147 | * @param value the value 148 | */ 149 | public void setValue(String column, Object value) { 150 | this.setValue(column, value.toString()); 151 | } 152 | 153 | /** 154 | * Add a line (only when the columnType is Vertical) 155 | */ 156 | public void addLine(){ 157 | this.lines++; 158 | } 159 | 160 | /** 161 | * Total lines (used only when the columnType is Vertical) 162 | * @return alls lines 163 | */ 164 | public int getLines() { 165 | return lines; 166 | } 167 | 168 | private static String format(String value) { 169 | String result = value; 170 | if (result.contains("\"")) { 171 | result = result.replace("\"", "\"\""); 172 | } 173 | return result; 174 | } 175 | 176 | @Override 177 | public long compile(File file) throws IOException { 178 | long sT = System.currentTimeMillis(); 179 | 180 | PrintWriter printWriter = new PrintWriter(file); 181 | String columnsLine = ""; 182 | Map indexMap = new HashMap<>(); 183 | int index = 0; 184 | for (String column : columns){ 185 | if(!columnsLine.isEmpty()) columnsLine += delemiter; 186 | columnsLine += column; 187 | indexMap.put(column, index++); 188 | } 189 | 190 | StringBuilder str = new StringBuilder(); 191 | if(type == ColumnType.VERTICAL) { 192 | str.append(columnsLine); 193 | Map lines = new HashMap<>(); 194 | for (Map.Entry> line : this.values.entrySet()) { 195 | int l = line.getKey(); 196 | lines.put(l, new String[columns.size()]); 197 | for (Map.Entry entry : line.getValue().entrySet()) { 198 | int id = indexMap.get(entry.getKey()); 199 | lines.get(l)[id] = entry.getValue(); 200 | } 201 | } 202 | int lastLine = 0; 203 | for (Map.Entry entry : lines.entrySet()) { 204 | if (lastLine != entry.getKey()) { 205 | str.append("\n"); 206 | lastLine = entry.getKey(); 207 | } 208 | String last = null; 209 | for (String value : entry.getValue()) { 210 | str.append((last != null ? delemiter : "") + value); 211 | last = value; 212 | } 213 | } 214 | }else if(type == ColumnType.HORIZONTAL){ 215 | Map> values = new HashMap<>(); 216 | columns.forEach(col -> values.put(col, new ArrayList<>())); 217 | for(Map map : this.values.values()){ 218 | map.entrySet().forEach(val -> values.get(val.getKey()).add(val.getValue())); 219 | } 220 | boolean bool = false; 221 | StringJoiner joiner; 222 | for (Map.Entry> entry : values.entrySet()){ 223 | joiner = new StringJoiner(delemiter); 224 | for (String val : entry.getValue()) 225 | joiner.add(val); 226 | str.append((bool ? "\n" : "")+entry.getKey()+delemiter+joiner.toString()); 227 | bool = true; 228 | } 229 | } 230 | printWriter.write(str.toString()); 231 | printWriter.close(); 232 | 233 | return (System.currentTimeMillis() - sT); 234 | } 235 | 236 | public enum ColumnType { VERTICAL, HORIZONTAL } 237 | 238 | } 239 | -------------------------------------------------------------------------------- /doc/index-files/index-17.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | V-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
A B C D E F G H I J L M P R S T V W  72 | 73 | 74 |

V

75 |
76 |
valueOf(String) - Static method in enum fr.sofianelecubeur.dataserializer.CompilationType
77 |
78 |
Returns the enum constant of this type with the specified name.
79 |
80 |
valueOf(String) - Static method in enum fr.sofianelecubeur.dataserializer.CSVFileSerializer.ColumnType
81 |
82 |
Returns the enum constant of this type with the specified name.
83 |
84 |
valueOf(String) - Static method in enum fr.sofianelecubeur.dataserializer.HashTextSerializer.Hash
85 |
86 |
Returns the enum constant of this type with the specified name.
87 |
88 |
values() - Static method in enum fr.sofianelecubeur.dataserializer.CompilationType
89 |
90 |
Returns an array containing the constants of this enum type, in 91 | the order they are declared.
92 |
93 |
values() - Static method in enum fr.sofianelecubeur.dataserializer.CSVFileSerializer.ColumnType
94 |
95 |
Returns an array containing the constants of this enum type, in 96 | the order they are declared.
97 |
98 |
values() - Static method in enum fr.sofianelecubeur.dataserializer.HashTextSerializer.Hash
99 |
100 |
Returns an array containing the constants of this enum type, in 101 | the order they are declared.
102 |
103 |
104 | A B C D E F G H I J L M P R S T V W 
105 | 106 |
107 | 108 | 109 | 110 | 111 | 112 | 113 | 122 |
123 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /doc/index-files/index-8.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | H-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
A B C D E F G H I J L M P R S T V W  72 | 73 | 74 |

H

75 |
76 |
hashCode() - Method in class fr.sofianelecubeur.dataserializer.FileInfo
77 |
 
78 |
hashCode() - Method in class fr.sofianelecubeur.dataserializer.util.Pair
79 |
 
80 |
HashTextSerializer - Class in fr.sofianelecubeur.dataserializer
81 |
82 |
Created by Sofiane on 26/07/2017.
83 |
84 |
HashTextSerializer(UUID, HashTextSerializer.Hash) - Constructor for class fr.sofianelecubeur.dataserializer.HashTextSerializer
85 |
 
86 |
HashTextSerializer() - Constructor for class fr.sofianelecubeur.dataserializer.HashTextSerializer
87 |
 
88 |
HashTextSerializer.Hash - Enum in fr.sofianelecubeur.dataserializer
89 |
 
90 |
HashUtils - Class in fr.sofianelecubeur.dataserializer.util
91 |
92 |
Created by Sofiane on 26/09/2017.
93 |
94 |
HashUtils() - Constructor for class fr.sofianelecubeur.dataserializer.util.HashUtils
95 |
 
96 |
97 | A B C D E F G H I J L M P R S T V W 
98 | 99 |
100 | 101 | 102 | 103 | 104 | 105 | 106 | 115 |
116 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /doc/index-files/index-5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | E-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
A B C D E F G H I J L M P R S T V W  72 | 73 | 74 |

E

75 |
76 |
encode(byte[]) - Static method in class fr.sofianelecubeur.dataserializer.base64.Base64Coder
77 |
78 |
Encodes a byte array into Base64 format.
79 |
80 |
encode(byte[], int) - Static method in class fr.sofianelecubeur.dataserializer.base64.Base64Coder
81 |
82 |
Encodes a byte array into Base64 format.
83 |
84 |
encode(byte[], int, int) - Static method in class fr.sofianelecubeur.dataserializer.base64.Base64Coder
85 |
86 |
Encodes a byte array into Base64 format.
87 |
88 |
encodeLines(byte[]) - Static method in class fr.sofianelecubeur.dataserializer.base64.Base64Coder
89 |
90 |
Encodes a byte array into Base 64 format and breaks the output into lines of 76 characters.
91 |
92 |
encodeLines(byte[], int, int, int, String) - Static method in class fr.sofianelecubeur.dataserializer.base64.Base64Coder
93 |
94 |
Encodes a byte array into Base 64 format and breaks the output into lines.
95 |
96 |
encodeString(String) - Static method in class fr.sofianelecubeur.dataserializer.base64.Base64Coder
97 |
98 |
Encodes a string into Base64 format.
99 |
100 |
equals(Object) - Method in class fr.sofianelecubeur.dataserializer.util.Pair
101 |
 
102 |
103 | A B C D E F G H I J L M P R S T V W 
104 | 105 |
106 | 107 | 108 | 109 | 110 | 111 | 112 | 121 |
122 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /doc/index-files/index-16.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | T-Index 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
A B C D E F G H I J L M P R S T V W  72 | 73 | 74 |

T

75 |
76 |
TextDeserializer<T> - Interface in fr.sofianelecubeur.dataserializer
77 |
78 |
Created by Sofiane on 25/06/2017.
79 |
80 |
TextSerializer<T,K> - Interface in fr.sofianelecubeur.dataserializer
81 |
82 |
Created by Sofiane on 25/06/2017.
83 |
84 |
toString() - Method in class fr.sofianelecubeur.dataserializer.Deserializer
85 |
 
86 |
toString() - Method in class fr.sofianelecubeur.dataserializer.Serializer
87 |
 
88 |
type(CompilationType) - Method in class fr.sofianelecubeur.dataserializer.FileDeserializerBuilder
89 |
90 |
Set the deserializer type
91 |
92 |
type(CompilationType) - Method in class fr.sofianelecubeur.dataserializer.FileSerializerBuilder
93 |
94 |
Set the serializer type
95 |
96 |
type2(CSVFileSerializer.ColumnType) - Method in class fr.sofianelecubeur.dataserializer.FileDeserializerBuilder
97 |
98 |
Set the column Type (Only used for CSV deserializer)
99 |
100 |
101 | A B C D E F G H I J L M P R S T V W 
102 | 103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 119 |
120 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /doc/fr/sofianelecubeur/dataserializer/TextDeserializer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | TextDeserializer 7 | 8 | 9 | 10 | 11 | 12 | 28 | 31 | 32 |
33 | 34 | 35 | 36 | 37 | 38 | 39 | 48 |
49 | 91 | 92 | 93 |
94 |
fr.sofianelecubeur.dataserializer
95 |

Interface TextDeserializer<T>

96 |
97 |
98 |
99 |
    100 |
  • 101 |
    102 |
    103 |
    public interface TextDeserializer<T>
    104 |
    Created by Sofiane on 25/06/2017.
    105 |
    106 |
    Author:
    107 |
    Sofiane
    108 |
    109 |
  • 110 |
111 |
112 |
113 | 136 |
137 |
138 | 161 |
162 |
163 | 164 | 165 |
166 | 167 | 168 | 169 | 170 | 171 | 172 | 181 |
182 | 224 | 225 | 226 | 227 | -------------------------------------------------------------------------------- /doc/fr/sofianelecubeur/dataserializer/TextSerializer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | TextSerializer 7 | 8 | 9 | 10 | 11 | 12 | 28 | 31 | 32 |
33 | 34 | 35 | 36 | 37 | 38 | 39 | 48 |
49 | 91 | 92 | 93 |
94 |
fr.sofianelecubeur.dataserializer
95 |

Interface TextSerializer<T,K>

96 |
97 |
98 |
99 |
    100 |
  • 101 |
    102 |
    All Known Implementing Classes:
    103 |
    HashTextSerializer
    104 |
    105 |
    106 |
    107 |
    public interface TextSerializer<T,K>
    108 |
    Created by Sofiane on 25/06/2017.
    109 |
    110 |
    Author:
    111 |
    Sofiane
    112 |
    113 |
  • 114 |
115 |
116 |
117 | 140 |
141 |
142 | 165 |
166 |
167 | 168 | 169 |
170 | 171 | 172 | 173 | 174 | 175 | 176 | 185 |
186 | 228 | 229 | 230 | 231 | -------------------------------------------------------------------------------- /doc/help-doc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | API Help 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

How This API Document Is Organized

73 |
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
74 |
75 |
76 |
    77 |
  • 78 |

    Overview

    79 |

    The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.

    80 |
  • 81 |
  • 82 |

    Package

    83 |

    Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:

    84 |
      85 |
    • Interfaces (italic)
    • 86 |
    • Classes
    • 87 |
    • Enums
    • 88 |
    • Exceptions
    • 89 |
    • Errors
    • 90 |
    • Annotation Types
    • 91 |
    92 |
  • 93 |
  • 94 |

    Class/Interface

    95 |

    Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    96 |
      97 |
    • Class inheritance diagram
    • 98 |
    • Direct Subclasses
    • 99 |
    • All Known Subinterfaces
    • 100 |
    • All Known Implementing Classes
    • 101 |
    • Class/interface declaration
    • 102 |
    • Class/interface description
    • 103 |
    104 |
      105 |
    • Nested Class Summary
    • 106 |
    • Field Summary
    • 107 |
    • Constructor Summary
    • 108 |
    • Method Summary
    • 109 |
    110 |
      111 |
    • Field Detail
    • 112 |
    • Constructor Detail
    • 113 |
    • Method Detail
    • 114 |
    115 |

    Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.

    116 |
  • 117 |
  • 118 |

    Annotation Type

    119 |

    Each annotation type has its own separate page with the following sections:

    120 |
      121 |
    • Annotation Type declaration
    • 122 |
    • Annotation Type description
    • 123 |
    • Required Element Summary
    • 124 |
    • Optional Element Summary
    • 125 |
    • Element Detail
    • 126 |
    127 |
  • 128 |
  • 129 |

    Enum

    130 |

    Each enum has its own separate page with the following sections:

    131 |
      132 |
    • Enum declaration
    • 133 |
    • Enum description
    • 134 |
    • Enum Constant Summary
    • 135 |
    • Enum Constant Detail
    • 136 |
    137 |
  • 138 |
  • 139 |

    Tree (Class Hierarchy)

    140 |

    There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.

    141 |
      142 |
    • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
    • 143 |
    • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
    • 144 |
    145 |
  • 146 |
  • 147 |

    Deprecated API

    148 |

    The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.

    149 |
  • 150 |
  • 151 |

    Index

    152 |

    The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.

    153 |
  • 154 |
  • 155 |

    Prev/Next

    156 |

    These links take you to the next or previous class, interface, package, or related page.

    157 |
  • 158 |
  • 159 |

    Frames/No Frames

    160 |

    These links show and hide the HTML frames. All pages are available with or without frames.

    161 |
  • 162 |
  • 163 |

    All Classes

    164 |

    The All Classes link shows all classes and interfaces except non-static nested types.

    165 |
  • 166 |
  • 167 |

    Serialized Form

    168 |

    Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.

    169 |
  • 170 |
  • 171 |

    Constant Field Values

    172 |

    The Constant Field Values page lists the static final fields and their values.

    173 |
  • 174 |
175 | This help file applies to API documentation generated using the standard doclet.
176 | 177 |
178 | 179 | 180 | 181 | 182 | 183 | 184 | 193 |
194 | 221 | 222 | 223 | 224 | --------------------------------------------------------------------------------