commit d7ea8c04f50376537c2ad281b7b9f7dae06fefb0
Author: Michal Horký <horkmi@students.zcu.cz>
Date:   Sun Apr 5 01:23:20 2020 +0200

    #7794
    
    Lehká uprava struktury v projektu. Hlavním důvodem commitu je prohrabání se testovacími daty od zákazníka - vyhovující testovací data ve složce test_input.

diff --git a/demo_mh/Deserializer/a.data b/demo_mh/Deserializer/a.data
new file mode 100644
index 0000000..53bc26d
Binary files /dev/null and b/demo_mh/Deserializer/a.data differ
diff --git a/demo_mh/Deserializer/b.data b/demo_mh/Deserializer/b.data
new file mode 100644
index 0000000..c3e84a1
Binary files /dev/null and b/demo_mh/Deserializer/b.data differ
diff --git a/demo_mh/Deserializer/data.out b/demo_mh/Deserializer/data.out
index 0b24b83..9cbc9b2 100644
Binary files a/demo_mh/Deserializer/data.out and b/demo_mh/Deserializer/data.out differ
diff --git a/demo_mh/Deserializer/results.json b/demo_mh/Deserializer/results.json
index f6d0918..0afb557 100644
--- a/demo_mh/Deserializer/results.json
+++ b/demo_mh/Deserializer/results.json
@@ -1 +1 @@
-{"parent":{"variables":{"str":"ABCD"},"name":"class serialize.Parent","interface":"java.io.Serializable"},"variables":{"x":10.0,"variable":{"variables":{"realNum":15.6},"name":"class serialize.Contain","interface":"java.io.Serializable"},"numberX":7},"name":"class serialize.Example","interface":"java.io.Serializable"}
\ No newline at end of file
+{"parent":{"variables":{"str":"ABCD","abc":true,"y":59.87},"name":"class serialize.Parent","interface":"java.io.Serializable"},"variables":{"x":10.0,"variable":{"variables":{"array":"NON_IMPLEMENTED"},"name":"class serialize.Contain","interface":"java.io.Serializable"},"numberX":7},"name":"class serialize.Example","interface":"java.io.Serializable"}
\ No newline at end of file
diff --git a/demo_mh/Deserializer/src/deserialize/ByteReader.java b/demo_mh/Deserializer/src/deserialize/ByteReader.java
new file mode 100644
index 0000000..c883a13
--- /dev/null
+++ b/demo_mh/Deserializer/src/deserialize/ByteReader.java
@@ -0,0 +1,93 @@
+package deserialize;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+// TODO osetreni vyjimek... a to celkove vsude. Zatim ponechavano z duvodu testovani.
+
+public class ByteReader {
+
+	private byte[] buffer;
+	private int actPos;
+	
+	public ByteReader(byte buffer[]) {
+		this.buffer = Arrays.copyOf(buffer, buffer.length);
+		actPos = 0;
+	}
+	
+	public boolean end() {
+		return actPos >= buffer.length;
+	}
+	
+	private byte readNext() {
+		return buffer[actPos++];
+	}
+	
+	private long readNumber(int bytes) {
+		long result = 0;
+		for (int i = (bytes - 1) * Byte.SIZE; i >= 0; i -= Byte.SIZE) {
+			result = result | ((readNext() & 0xFF) << i);
+		}
+		return result;
+	}
+	
+	public byte readByte() {
+		return readNext();
+	}
+	
+	public char readUnsignedByte() {
+		return (char) readNumber(Byte.BYTES);
+	}
+	
+	public short readShort() {
+		return (short) readNumber(Short.BYTES);
+	}
+	
+	public char readChar() {
+		return (char) readShort();
+	}
+	
+	public int readInt() {
+		return (int) readNumber(Integer.BYTES);
+	}
+	
+	public long readLong() {
+		return readNumber(Long.BYTES);
+	}
+	
+	public String readString(long length) {
+		String str = "";
+		for (int i = 0; i < length; i++) {
+			str += (char) readByte();
+		}
+		return str;
+	}
+	
+	public String readUtf() {
+		short length = readShort();
+		return readString(length);
+	}
+	
+	public String readLongUtf() {
+		long length = readLong();
+		return readString(length);
+	}
+	
+	public float readFloat() {
+		return Float.intBitsToFloat(readInt());
+	}
+	
+	public double readDouble() {
+		// return Double.longBitsToDouble(readLong()); DOESNT WORK...
+		byte b[] = new byte[Long.BYTES];
+		for (int i = 0; i < b.length; i++) {
+			b[i] = readByte();
+		}
+		return ByteBuffer.wrap(b).getDouble();
+	}
+	
+	public boolean readBoolean() {
+		return readByte() != 0;
+	}
+	
+}
diff --git a/demo_mh/Deserializer/src/deserialize/ClassDescription.java b/demo_mh/Deserializer/src/deserialize/ClassDescription.java
index 71ecb8b..c467ea6 100644
--- a/demo_mh/Deserializer/src/deserialize/ClassDescription.java
+++ b/demo_mh/Deserializer/src/deserialize/ClassDescription.java
@@ -21,6 +21,18 @@ public class ClassDescription {
 	private List<Variable> variables = new ArrayList<Variable>();
 	private int actVariableIndex = -1;
 	
+	
+	
+	public List<ClassDescription> getParents() {
+		return parents;
+	}
+	
+	public List<Variable> getVariables() {
+		return variables;
+	}
+	
+	
+	
 	public Variable nextVariable() {
 		if (++actVariableIndex < variables.size()) {
 			return variables.get(actVariableIndex);
diff --git a/demo_mh/Deserializer/src/deserialize/DataType.java b/demo_mh/Deserializer/src/deserialize/DataType.java
index ed8b1f9..11fed24 100644
--- a/demo_mh/Deserializer/src/deserialize/DataType.java
+++ b/demo_mh/Deserializer/src/deserialize/DataType.java
@@ -3,7 +3,7 @@ package deserialize;
 import java.util.HashMap;
 
 public class DataType {
-
+	
 	public final static HashMap<Character, String> primTypeCodes;
 	public final static HashMap<Character, String> objTypeCodes;
 	
diff --git a/demo_mh/Deserializer/src/deserialize/Grammar.java b/demo_mh/Deserializer/src/deserialize/Grammar.java
index b6227f4..11a526a 100644
--- a/demo_mh/Deserializer/src/deserialize/Grammar.java
+++ b/demo_mh/Deserializer/src/deserialize/Grammar.java
@@ -1,5 +1,6 @@
 package deserialize;
 
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -36,76 +37,10 @@ public class Grammar {
 	final static byte SC_EXTERNALIZABLE = 0x04;
 	final static byte SC_ENUM = 0x10;
 
-	private List<Byte> buffer;
-	public Grammar(byte buffer[]) {
-		this.buffer = new ArrayList<Byte>();
-		for (int i = 0; i < buffer.length; i++) {
-			this.buffer.add(buffer[i]);
-		}
-	}
-	
-	
-	private byte takeFirst() {
-		return buffer.remove(0);
-	}
-	
-	public byte readByte() {
-		return takeFirst();
-	}
-	
-	private long readNumber(int bytes) {
-		long result = 0;
-		for (int i = (bytes - 1) * Byte.SIZE; i >= 0; i -= Byte.SIZE) {
-			result = result | ((takeFirst() & 0xFF) << i);
-		}
-		return result;
-	}
-	
-	public char readUnsignedByte() {
-		return (char) readNumber(Byte.BYTES);
-	}
-	
-	public short readShort() {
-		return (short) readNumber(Short.BYTES);
-	}
-	
-	public int readInt() {
-		return (int) readNumber(Integer.BYTES);
-	}
+	private ByteReader reader;
 	
-	public long readLong() {
-		return readNumber(Long.BYTES);
-	}
-	
-	public String readString(long length) {
-		String str = "";
-		for (int i = 0; i < length; i++) {
-			str += (char) readByte();
-		}
-		return str;
-	}
-	
-	public String readUtf() {
-		short length = readShort();
-		return readString(length);
-	}
-	
-	public String readLongUtf() {
-		long length = readLong();
-		return readString(length);
-	}
-	
-	public float readFloat() {
-		return Float.intBitsToFloat(readInt());
-	}
-	
-	public double readDouble() {
-		return Double.longBitsToDouble(readLong());
-	}
-	
-	public boolean readBoolean() {
-		// TODO zkontrolovat
-		return readByte() != 0;
+	public Grammar(byte buffer[]) {
+		reader = new ByteReader(buffer);
 	}
 	
 	
@@ -113,12 +48,13 @@ public class Grammar {
 	ClassDescription actClass = null;
 	
 	public JSONObject process() {
-		System.out.println("Kontrola hlavicky souboru: " + (readShort() == STREAM_MAGIC && readShort() == STREAM_VERSION));
+		System.out.println("Kontrola hlavicky souboru: " + (reader.readShort() == STREAM_MAGIC && reader.readShort() == STREAM_VERSION));
 		
-		while (!buffer.isEmpty()) {
+		while (!reader.end()) {
 			try {
 				object();
 			} catch (Exception e) {
+				e.printStackTrace();
 				break;
 			}
 		}
@@ -132,7 +68,7 @@ public class Grammar {
     // classDesc for the current object
 	public Object object() {
 		Object retValue;
-		byte b = readByte();
+		byte b = reader.readByte();
 		switch (b) {
 			case TC_OBJECT: {
 					System.out.println("X1");
@@ -181,18 +117,18 @@ public class Grammar {
 					System.out.println("X3");
 					ClassDescription desc = (ClassDescription) object();
 					// TODO int size = readInt();
-					retValue = desc.className;; // TODO + "[" + size + "]";
+					retValue = desc; // TODO + "[" + size + "]";
 				}
 				break;
 			case TC_STRING: {
 					System.out.println("X4");
-					String str = readUtf();
+					String str = reader.readUtf();
 					retValue = str;
 				}
 				break;
 			case TC_LONGSTRING: {
 					System.out.println("X5");
-					String str = readLongUtf();
+					String str = reader.readLongUtf();
 					retValue = str;
 				}
 				break;
@@ -209,9 +145,9 @@ public class Grammar {
 			case TC_CLASSDESC: {
 					System.out.println("X7");
 					ClassDescription desc = new ClassDescription();
-					desc.className = readUtf();
-					desc.serialVersionUID = readLong();
-					desc.flags = readByte();
+					desc.className = reader.readUtf();
+					desc.serialVersionUID = reader.readLong();
+					desc.flags = reader.readByte();
 					desc.isClass = true;
 					desc.setVariables(fields());
 					
@@ -228,8 +164,8 @@ public class Grammar {
 				break;
 			case TC_PROXYCLASSDESC: {
 					System.out.println("X8");
-					int count = readInt();
-					String name = readUtf();
+					int count = reader.readInt();
+					String name = reader.readUtf();
 					retValue = name + "[" + +count + "]";
 					// TODO object(null); classDesc();
 					
@@ -249,25 +185,24 @@ public class Grammar {
 						}
 						
 						switch (actVar.getType()) {
-						case 'B': actVar.setValue(readByte()); break;
-						case 'C': actVar.setValue((char) readByte()); break;
-						case 'D': actVar.setValue(readDouble()); break;
-						case 'F': actVar.setValue(readFloat()); break;
-						case 'I': actVar.setValue(readInt()); break;
-						case 'J': actVar.setValue(readLong()); break;
-						case 'S': actVar.setValue(readShort()); break;
-						case 'Z': actVar.setValue(readBoolean()); break;
+						case 'B': actVar.setValue(reader.readByte()); break;
+						case 'C': actVar.setValue((char) reader.readByte()); break;
+						case 'D': actVar.setValue(reader.readDouble()); break;
+						case 'F': actVar.setValue(reader.readFloat()); break;
+						case 'I': actVar.setValue(reader.readInt()); break;
+						case 'J': actVar.setValue(reader.readLong()); break;
+						case 'S': actVar.setValue(reader.readShort()); break;
+						case 'Z': actVar.setValue(reader.readBoolean()); break;
 						case '[':
-							// int count = readShort();
-							// TODO
-							for (int i = 0; i < 3; i++) {
-								object();
-								// System.out.println("DEF: " + " " + (char) xxx + " " + xxx);
-							}
-							int count = readInt();
+							ClassDescription desccc = (ClassDescription) object();
+							
+							object(); // END BLOK
+							object(); // NULL
+							
+							int count = reader.readInt();
 							System.out.println("------------- VELIKOST POLE = " + count);
 							for (int i = 0; i < count; i++) {
-								System.out.println("------------- HODNOTA = " + (char) readShort());
+								System.out.println("------------- HODNOTA = " + reader.readChar());
 							}
 							//actVar.setValue(readByte());
 							break;
@@ -297,14 +232,14 @@ public class Grammar {
 				break;
 			case TC_BLOCKDATA: {
 					System.out.println("X13");
-					char size = readUnsignedByte();
+					char size = reader.readUnsignedByte();
 					// (unsigned byte)<size> (byte)[size];
 					retValue = "byte [" + (int) size + "]";
 				}
 				break;
 			case TC_BLOCKDATALONG: {
 					System.out.println("X14");
-					int size = readInt();
+					int size = reader.readInt();
 					// (int)<size> (byte)[size];
 					retValue = "byte [" + size + "]";
 				}
@@ -326,10 +261,10 @@ public class Grammar {
 	public List<Variable> fields() {
 		List<Variable> variables = new ArrayList<Variable>();
 		
-		short count = readShort();
+		short count = reader.readShort();
 		for (int i = 0; i < count; i++) {
-			char type = (char) readByte();
-			String variable = readUtf();
+			char type = (char) reader.readByte();
+			String variable = reader.readUtf();
 			String typeName = null;
 			if (!DataType.isPrimaryType(type))
 				typeName = (String) object();
diff --git a/demo_mh/Deserializer/src/deserialize/ToJSON.java b/demo_mh/Deserializer/src/deserialize/ToJSON.java
index 5c6523f..9c95929 100644
--- a/demo_mh/Deserializer/src/deserialize/ToJSON.java
+++ b/demo_mh/Deserializer/src/deserialize/ToJSON.java
@@ -67,6 +67,8 @@ public class ToJSON extends Thread {
 			System.out.println("Chyba pri otevirani (uzavirani) streamu pri pokusu o klasickou deserializaci.");
 			e.printStackTrace();
 			
+			return false;
+			
 		} catch (Exception e) {
 			
 			// Others: ClassNotFoundException, ClassCastException, ...
@@ -100,8 +102,10 @@ public class ToJSON extends Thread {
 	    
 	    try {
 	    	if (entry != null) {
-		    	array = new byte[(int) entry.getSize()];
-				zipInputStream.read(array);
+	    		//array = new byte[(int) entry.getSize()];
+				array = entry.getExtra();
+				System.out.println(array.length);
+	    		//zipInputStream.read(array);
 				zipInputStream.close();
 		    } else {
 		    	array = new byte[(int) input.length()];
diff --git a/demo_mh/Deserializer/src/serialize/Contain.java b/demo_mh/Deserializer/src/serialize/Contain.java
index d1c1398..b2fe51a 100644
--- a/demo_mh/Deserializer/src/serialize/Contain.java
+++ b/demo_mh/Deserializer/src/serialize/Contain.java
@@ -6,7 +6,7 @@ public class Contain implements Serializable {
 
 	private static final long serialVersionUID = 1L;
 	
-	// TODO jeste nefunguje char array[] = new char[] {'W', 'X', 'Y', 'Z'};
-	float realNum = 15.6f;
+	char array[] = new char[] {'W', 'X', 'Y', 'Z'};
+	// float realNum = 15.6f;
 	
 }
diff --git a/demo_mh/Deserializer/src/serialize/Parent.java b/demo_mh/Deserializer/src/serialize/Parent.java
index a0ad5cd..da890b4 100644
--- a/demo_mh/Deserializer/src/serialize/Parent.java
+++ b/demo_mh/Deserializer/src/serialize/Parent.java
@@ -7,5 +7,7 @@ public class Parent implements Serializable {
 	private static final long serialVersionUID = 1L;
 	
 	String str = "ABCD";
+	boolean abc = true;
+	double y = 59.87;
 	
 }
diff --git a/demo_mh/Deserializer/test_input/GK_REPORT_ARCHIVE_202004031533.md-1164.data b/demo_mh/Deserializer/test_input/GK_REPORT_ARCHIVE_202004031533.md-1164.data
new file mode 100644
index 0000000..53bc26d
Binary files /dev/null and b/demo_mh/Deserializer/test_input/GK_REPORT_ARCHIVE_202004031533.md-1164.data differ
diff --git a/demo_mh/Deserializer/test_input/GK_REPORT_ARCHIVE_202004031533.md-1165.data b/demo_mh/Deserializer/test_input/GK_REPORT_ARCHIVE_202004031533.md-1165.data
new file mode 100644
index 0000000..c3e84a1
Binary files /dev/null and b/demo_mh/Deserializer/test_input/GK_REPORT_ARCHIVE_202004031533.md-1165.data differ
