public static String joinRecordsIntoString( long startRecordId, List<LegacyDynamicRecord> legacyDynamicRecords) { Map<Long, LegacyDynamicRecord> recordsMap = new HashMap<Long, LegacyDynamicRecord>(); long recordToFind = startRecordId; for (LegacyDynamicRecord record : legacyDynamicRecords) { recordsMap.put(record.getId(), record); } List<char[]> charList = new LinkedList<char[]>(); while (recordToFind != Record.NO_NEXT_BLOCK.intValue()) { LegacyDynamicRecord record = recordsMap.get(recordToFind); if (!record.isCharData()) { ByteBuffer buf = ByteBuffer.wrap(record.getData()); char[] chars = new char[record.getData().length / 2]; buf.asCharBuffer().get(chars); charList.add(chars); } else { charList.add(record.getDataAsChar()); } recordToFind = record.getNextBlock(); } StringBuffer buf = new StringBuffer(); for (char[] str : charList) { buf.append(str); } return buf.toString(); }
public Object getArrayFor(LegacyPropertyRecord propertyRecord) { long recordToFind = propertyRecord.getPropBlock(); Map<Long, LegacyDynamicRecord> recordsMap = new HashMap<Long, LegacyDynamicRecord>(); for (LegacyDynamicRecord record : readDynamicRecords(propertyRecord)) { recordsMap.put(record.getId(), record); } List<byte[]> byteList = new LinkedList<byte[]>(); int totalSize = 0; while (recordToFind != Record.NO_NEXT_BLOCK.intValue()) { LegacyDynamicRecord record = recordsMap.get(recordToFind); if (!record.isCharData()) { ByteBuffer buf = ByteBuffer.wrap(record.getData()); byte[] bytes = new byte[record.getData().length]; totalSize += bytes.length; buf.get(bytes); byteList.add(bytes); } else { throw new InvalidRecordException("Expected byte data on record " + record); } recordToFind = record.getNextBlock(); } byte[] bArray = new byte[totalSize]; int offset = 0; for (byte[] currentArray : byteList) { System.arraycopy(currentArray, 0, bArray, offset, currentArray.length); offset += currentArray.length; } return arrayPropertyStore.getRightArray(bArray); }
public List<LegacyDynamicRecord> readDynamicRecords(LegacyPropertyRecord record) { if (record.getType() == LegacyPropertyType.STRING) { List<LegacyDynamicRecord> stringRecords = stringPropertyStore.getPropertyChain(record.getPropBlock()); for (LegacyDynamicRecord stringRecord : stringRecords) { stringRecord.setType(PropertyType.STRING.intValue()); } return stringRecords; } else if (record.getType() == LegacyPropertyType.ARRAY) { List<LegacyDynamicRecord> arrayRecords = arrayPropertyStore.getPropertyChain(record.getPropBlock()); for (LegacyDynamicRecord arrayRecord : arrayRecords) { arrayRecord.setType(PropertyType.ARRAY.intValue()); } return arrayRecords; } return null; }