From cc6b8536efa68fe125077ca938b3a20da39f67fd Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Fri, 16 Feb 2018 15:27:23 +0200 Subject: [PATCH] Removed unused but similarly buggy code to fb2f890c from WriteBindings refs #7770 Change-Id: I3750d0272c3fd4a228fe2c943dcf331955cbcee5 --- .../simantics/db/common/WriteBindings.java | 292 +----------------- 1 file changed, 1 insertion(+), 291 deletions(-) diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/WriteBindings.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/WriteBindings.java index e9ecce63c..2939f12cc 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/WriteBindings.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/WriteBindings.java @@ -257,305 +257,15 @@ public class WriteBindings { public TRANSFERABLE_GRAPH_SERIALIZER() { super(TRANSFERABLE_GRAPH_BINDING.INSTANCE); } - - static int writeUTF(String str, byte[] bytearr, int byteIndex) throws IOException { - - int strlen = str.length(); - int utflen = 0; - int c; - int count = byteIndex; - - /* use charAt instead of copying String to char array */ - for (int i = 0; i < strlen; i++) { - c = str.charAt(i); - if ((c >= 0x0001) && (c <= 0x007F)) { - utflen++; - } else if (c > 0x07FF) { - utflen += 3; - } else { - utflen += 2; - } - } - - if (utflen > 65535) - throw new UTFDataFormatException( - "encoded string too long: " + utflen + " bytes"); -// byte[] bytearr = new byte[utflen+2]; - - if(utflen < 0x80) { - bytearr[count++] = ((byte)utflen); - } - else { - utflen -= 0x80; - if(utflen < 0x4000) { - bytearr[count++] = (byte)( ((utflen&0x3f) | 0x80) ); - bytearr[count++] = (byte)( (utflen>>>6) ); - } - else { - utflen -= 0x4000; - if(utflen < 0x200000) { - bytearr[count++] = (byte)( ((utflen&0x1f) | 0xc0) ); - bytearr[count++] = (byte)( ((utflen>>>5)&0xff) ); - bytearr[count++] = (byte)( ((utflen>>>13)&0xff) ); - } - else { - utflen -= 0x200000; - if(utflen < 0x10000000) { - bytearr[count++] = (byte)( ((utflen&0x0f) | 0xe0) ); - bytearr[count++] = (byte)( ((utflen>>>4)&0xff) ); - bytearr[count++] = (byte)( ((utflen>>>12)&0xff) ); - bytearr[count++] = (byte)( ((utflen>>>20)&0xff) ); - } - else { - utflen -= 0x10000000; - bytearr[count++] = (byte)( ((utflen&0x07) | 0xf0) ); - bytearr[count++] = (byte)( ((utflen>>>3)&0xff) ); - bytearr[count++] = (byte)( ((utflen>>>11)&0xff) ); - bytearr[count++] = (byte)( ((utflen>>>19)&0xff) ); - bytearr[count++] = (byte)( ((utflen>>>27)&0xff) ); - } - } - } - } - - int i=0; - for (i=0; i= 0x0001) && (c <= 0x007F))) break; - bytearr[count++] = (byte) c; - } - - for (;i < strlen; i++){ - c = str.charAt(i); - if ((c >= 0x0001) && (c <= 0x007F)) { - bytearr[count++] = (byte) c; - - } else if (c > 0x07FF) { - bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F)); - bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F)); - bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F)); - } else { - bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F)); - bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F)); - } - } - - return count - byteIndex; - - } - @Override public byte[] serialize(Object obj) throws IOException { - TransferableGraph1 tg = (TransferableGraph1)obj; - return Bindings .getSerializerUnchecked(TransferableGraph1.class) .serialize(tg); -/* - // 16 = resourceCount + 3 arrays -// long start = System.nanoTime(); - int actualSize = 16 + 8*tg.values.length + 4*tg.statements.length + 5*tg.identities.length; - for(Value v : tg.values) actualSize += v.value.length; - for(Identity id : tg.identities) { - if(id.definition instanceof Internal) actualSize += (4 + ((Internal)id.definition).name.length() + 5); - else if(id.definition instanceof External) actualSize += (4 + ((External)id.definition).name.length() + 5); - else if(id.definition instanceof Root) actualSize += (((Root)id.definition).name.length() + ((Root)id.definition).type.length() + 10); - else if(id.definition instanceof Optional) actualSize += (4 + ((Optional)id.definition).name.length() + 5); - } -// long end = System.nanoTime() - start; -// System.err.println("size took " + 1e-9*end); - -// long start2 = System.nanoTime(); - - - byte[] bytes = new byte[actualSize]; - int byteIndex = 0; - - int i = tg.resourceCount; - - bytes[byteIndex+3] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+2] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+1] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex] = (byte)(i & 0xFF);i >>>= 8; - byteIndex+=4; - - i = tg.identities.length; - - bytes[byteIndex+3] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+2] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+1] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex] = (byte)(i & 0xFF);i >>>= 8; - byteIndex+=4; - - for(Identity id : tg.identities) { - - i = id.resource; - bytes[byteIndex+3] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+2] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+1] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex] = (byte)(i & 0xFF);i >>>= 8; - byteIndex+=4; - - if(id.definition instanceof Internal) { - - Internal r = (Internal)id.definition; - - bytes[byteIndex++] = 3; - - i = r.parent; - bytes[byteIndex+3] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+2] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+1] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex] = (byte)(i & 0xFF);i >>>= 8; - byteIndex+=4; - - byteIndex += writeUTF(r.name, bytes, byteIndex); - - } else if(id.definition instanceof External) { - - External r = (External)id.definition; - - bytes[byteIndex++] = 1; - - i = r.parent; - bytes[byteIndex+3] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+2] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+1] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex] = (byte)(i & 0xFF);i >>>= 8; - byteIndex+=4; - - byteIndex += writeUTF(r.name, bytes, byteIndex); - - } else if(id.definition instanceof Root) { - - bytes[byteIndex++] = 0; - - Root r = (Root)id.definition; - byteIndex += writeUTF(r.name, bytes, byteIndex); - byteIndex += writeUTF(r.type, bytes, byteIndex); - - } else if(id.definition instanceof Optional) { - - Optional r = (Optional)id.definition; - - bytes[byteIndex++] = 2; - - i = r.parent; - bytes[byteIndex+3] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+2] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+1] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex] = (byte)(i & 0xFF);i >>>= 8; - byteIndex+=4; - - byteIndex += writeUTF(r.name, bytes, byteIndex); - - } - - } - - i = tg.statements.length; - bytes[byteIndex+3] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+2] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+1] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex] = (byte)(i & 0xFF);i >>>= 8; - byteIndex+=4; - - for(int s : tg.statements) { - i = s; - bytes[byteIndex+3] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+2] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+1] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex] = (byte)(i & 0xFF);i >>>= 8; - byteIndex+=4; - } - - i = tg.values.length; - bytes[byteIndex+3] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+2] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+1] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex] = (byte)(i & 0xFF);i >>>= 8; - byteIndex+=4; - - for(Value v : tg.values) { - - i = v.resource; - bytes[byteIndex+3] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+2] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+1] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex] = (byte)(i & 0xFF);i >>>= 8; - byteIndex+=4; - - i = v.value.length; - bytes[byteIndex+3] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+2] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex+1] = (byte)(i & 0xFF);i >>>= 8; - bytes[byteIndex] = (byte)(i & 0xFF);i >>>= 8; - byteIndex+=4; - - System.arraycopy(v.value, 0, bytes, byteIndex, v.value.length); - byteIndex += v.value.length; - - } - -// return bytes; - -// byte[] result = new byte[byteIndex]; -// System.arraycopy(bytes, 0, result, 0, byteIndex); -// -// byte[] result = Arrays.copyOf(bytes, byteIndex); - -// long end2 = System.nanoTime() - start2; -// System.err.println("size2 took " + 1e-9*end2); - - return bytes; - -// long[] data = (long[])obj; -// byte[] result = new byte[4+8*data.length]; -// -// int len = data.length; -// -// result[3] = (byte)(len & 0xFF); -// len >>>= 8; -// result[2] = (byte)(len & 0xFF); -// len >>>= 8; -// result[1] = (byte)(len & 0xFF); -// len >>>= 8; -// result[0] = (byte)(len & 0xFF); -// -// int index = 4; -// -// for(int i=0;i>>= 8; -// result[index+6] = (byte)(l & 0xFF); -// l >>>= 8; -// result[index+5] = (byte)(l & 0xFF); -// l >>>= 8; -// result[index+4] = (byte)(l & 0xFF); -// l >>>= 8; -// result[index+3] = (byte)(l & 0xFF); -// l >>>= 8; -// result[index+2] = (byte)(l & 0xFF); -// l >>>= 8; -// result[index+1] = (byte)(l & 0xFF); -// l >>>= 8; -// result[index] = (byte)(l & 0xFF); -// l >>>= 8; -// -// index += 8; -// -// } -// -// return result; -*/ } - - + final private String utf(byte[] bytes) { char[] chars = new char[bytes.length]; -- 2.43.2