public static long encodeArrayStructure(ArrayStructure as, OutputStream os) throws java.io.IOException { long size = 0; ArrayStructureBB dataBB = StructureDataDeep.copyToArrayBB(as, null); // LOOK what should the bo be ?? List<String> ss = new ArrayList<String>(); List<Object> heap = dataBB.getHeap(); List<Integer> count = new ArrayList<Integer>(); if (heap != null) { for (Object ho : heap) { if (ho instanceof String) { count.add(1); ss.add((String) ho); } else if (ho instanceof String[]) { String[] hos = (String[]) ho; count.add(hos.length); for (String s : hos) ss.add(s); } } } ByteBuffer bb = dataBB.getByteBuffer(); NcStreamProto.StructureData proto = NcStream.encodeStructureDataProto(bb.array(), count, ss); byte[] datab = proto.toByteArray(); size += NcStream.writeVInt(os, datab.length); // proto len os.write(datab); // proto size += datab.length; // System.out.printf("encodeArrayStructure write sdata size= %d%n", datab.length); return size; }
public static long encodeArrayStructure(ArrayStructure as, OutputStream os) throws java.io.IOException { long size = 0; ArrayStructureBB dataBB = IospHelper.makeArrayBB(as); List<String> ss = new ArrayList<String>(); List<Object> heap = dataBB.getHeap(); List<Integer> count = new ArrayList<Integer>(); if (heap != null) { for (Object ho : heap) { if (ho instanceof String) { count.add(1); ss.add((String) ho); } else if (ho instanceof String[]) { String[] hos = (String[]) ho; count.add(hos.length); for (String s : hos) ss.add(s); } } } ByteBuffer bb = dataBB.getByteBuffer(); NcStreamProto.StructureData proto = NcStream.encodeStructureDataProto(bb.array(), count, ss); byte[] datab = proto.toByteArray(); size += NcStream.writeVInt(os, datab.length); // proto len os.write(datab); // proto size += datab.length; // System.out.printf("encodeArrayStructure write sdata size= %d%n", datab.length); return size; }
public static long encodeArrayStructure(ArrayStructure as, ByteOrder bo, OutputStream os) throws java.io.IOException { long size = 0; ArrayStructureBB dataBB = StructureDataDeep.copyToArrayBB(as, bo, true); // force canonical packing List<String> ss = new ArrayList<>(); List<Object> heap = dataBB.getHeap(); List<Integer> count = new ArrayList<>(); if (heap != null) { for (Object ho : heap) { if (ho instanceof String) { count.add(1); ss.add((String) ho); } else if (ho instanceof String[]) { String[] hos = (String[]) ho; count.add(hos.length); for (String s : hos) ss.add(s); } } } // LOOK optionally compress StructureMembers sm = dataBB.getStructureMembers(); ByteBuffer bb = dataBB.getByteBuffer(); NcStreamProto.StructureData proto = NcStream.encodeStructureDataProto(bb.array(), count, ss, (int) as.getSize(), sm.getStructureSize()); byte[] datab = proto.toByteArray(); size += NcStream.writeVInt(os, datab.length); // proto len os.write(datab); // proto size += datab.length; // System.out.printf("encodeArrayStructure write sdata size= %d%n", datab.length); return size; }