@Test public void testReadAttribute() throws IOException { Subject subject = new Subject(); Tag preparedTag = new Tag("abc", "123"); ByteBuffer mem = ByteBuffer.allocate(2 + preparedTag.getValue().length() * 2); subject.writeAttribute(mem, preparedTag.getValue().length(), preparedTag); Assert.assertEquals(mem.limit(), mem.position()); mem.rewind(); Tag reat = subject.readAttribute(mem, preparedTag.getValue().length(), new ArrayList<Tag>()); Assert.assertNotNull(reat); Assert.assertEquals(preparedTag.getKey(), reat.getKey()); Assert.assertEquals(preparedTag.getValue(), reat.getValue()); }
protected Tag readAttribute(final ByteBuffer mem, final int aCharCount, final List<Tag> aTagList) { char[] tagValue = new char[aCharCount]; short tagKeyID = mem.getShort(); for (int i = 0; i < aCharCount; i++) { tagValue[i] = mem.getChar(); } String value = new String(tagValue).replaceAll("" + ILLEGALCHAR, ""); if (tagKeyID == (Short.MIN_VALUE + 1)) { if (aTagList.size() == 0) { throw new IllegalStateException("First tag of an entity cannot be a continuation!"); } Tag oldTag = aTagList.remove(aTagList.size() - 1); return new Tag(oldTag.getKey(), oldTag.getValue() + value.replaceAll("" + ILLEGALCHAR, "")); } if (tagKeyID != Short.MIN_VALUE) { String tagKey = getAttrNamesFile().getAttributeName(tagKeyID); if (tagKey != null && value != null) { return new Tag(tagKey, value); } } return null; }
AbstractEntityFile extends FixedRecordFile { protected Tag readAttribute(final ByteBuffer mem, final int aCharCount, final List<Tag> aTagList) { char[] tagValue = new char[aCharCount]; short tagKeyID = mem.getShort(); for (int i = 0; i < aCharCount; i++) { tagValue[i] = mem.getChar(); } String value = new String(tagValue).replaceAll("" + ILLEGALCHAR, ""); if (tagKeyID == (Short.MIN_VALUE + 1)) { if (aTagList.size() == 0) { throw new IllegalStateException("First tag of an entity cannot be a continuation!"); } Tag oldTag = aTagList.remove(aTagList.size() - 1); return new Tag(oldTag.getKey(), oldTag.getValue() + value.replaceAll("" + ILLEGALCHAR, "")); } if (tagKeyID != Short.MIN_VALUE) { String tagKey = getAttrNamesFile().getAttributeName(tagKeyID); if (tagKey != null && value != null) { return new Tag(tagKey, value); } } return null; } }
AbstractEntityFile extends FixedRecordFile { protected Tag readAttribute(final ByteBuffer mem, final int aCharCount, final List<Tag> aTagList) { char[] tagValue = new char[aCharCount]; short tagKeyID = mem.getShort(); for (int i = 0; i < aCharCount; i++) { tagValue[i] = mem.getChar(); } String value = new String(tagValue).replaceAll("" + ILLEGALCHAR, ""); if (tagKeyID == (Short.MIN_VALUE + 1)) { if (aTagList.size() == 0) { throw new IllegalStateException("First tag of an entity cannot be a continuation!"); } Tag oldTag = aTagList.remove(aTagList.size() - 1); return new Tag(oldTag.getKey(), oldTag.getValue() + value.replaceAll("" + ILLEGALCHAR, "")); } if (tagKeyID != Short.MIN_VALUE) { String tagKey = getAttrNamesFile().getAttributeName(tagKeyID); if (tagKey != null && value != null) { return new Tag(tagKey, value); } } return null; } protected  AbstractEntityFile(final File aFileName,
            final IIDIndexFile anIndex,
            final AttrNames anAttrNamesFile); }
AbstractEntityFile extends FixedRecordFile { protected Tag readAttribute(final ByteBuffer mem, final int aCharCount, final List<Tag> aTagList) { char[] tagValue = new char[aCharCount]; short tagKeyID = mem.getShort(); for (int i = 0; i < aCharCount; i++) { tagValue[i] = mem.getChar(); } String value = new String(tagValue).replaceAll("" + ILLEGALCHAR, ""); if (tagKeyID == (Short.MIN_VALUE + 1)) { if (aTagList.size() == 0) { throw new IllegalStateException("First tag of an entity cannot be a continuation!"); } Tag oldTag = aTagList.remove(aTagList.size() - 1); return new Tag(oldTag.getKey(), oldTag.getValue() + value.replaceAll("" + ILLEGALCHAR, "")); } if (tagKeyID != Short.MIN_VALUE) { String tagKey = getAttrNamesFile().getAttributeName(tagKeyID); if (tagKey != null && value != null) { return new Tag(tagKey, value); } } return null; } protected  AbstractEntityFile(final File aFileName,
            final IIDIndexFile anIndex,
            final AttrNames anAttrNamesFile); int getUsedRecordCount(final long firstRecordNr, final long anElementID); boolean isRecordUnused(final ByteBuffer record); void setIndex(final IIDIndexFile aIndex); List<Object> prepareTagList(final Collection<Tag> aTagList, final int aNumtagvalchars); }
AbstractEntityFile extends FixedRecordFile { protected Tag readAttribute(final ByteBuffer mem, final int aCharCount, final List<Tag> aTagList) { char[] tagValue = new char[aCharCount]; short tagKeyID = mem.getShort(); for (int i = 0; i < aCharCount; i++) { tagValue[i] = mem.getChar(); } String value = new String(tagValue).replaceAll("" + ILLEGALCHAR, ""); if (tagKeyID == (Short.MIN_VALUE + 1)) { if (aTagList.size() == 0) { throw new IllegalStateException("First tag of an entity cannot be a continuation!"); } Tag oldTag = aTagList.remove(aTagList.size() - 1); return new Tag(oldTag.getKey(), oldTag.getValue() + value.replaceAll("" + ILLEGALCHAR, "")); } if (tagKeyID != Short.MIN_VALUE) { String tagKey = getAttrNamesFile().getAttributeName(tagKeyID); if (tagKey != null && value != null) { return new Tag(tagKey, value); } } return null; } protected  AbstractEntityFile(final File aFileName,
            final IIDIndexFile anIndex,
            final AttrNames anAttrNamesFile); int getUsedRecordCount(final long firstRecordNr, final long anElementID); boolean isRecordUnused(final ByteBuffer record); void setIndex(final IIDIndexFile aIndex); List<Object> prepareTagList(final Collection<Tag> aTagList, final int aNumtagvalchars);  }