| | |
| | | { |
| | | is = ((URI) obj).toURL().openStream(); |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | while (bsb.append(is, 2048) != -1) |
| | | while (bsb.appendBytes(is, 2048) != -1) |
| | | { |
| | | // do nothing |
| | | } |
| | |
| | | for (final Object definition : remainingAttrs) |
| | | { |
| | | final ByteStringBuilder sb = new ByteStringBuilder(); |
| | | sb.append(definition); |
| | | sb.appendObject(definition); |
| | | try |
| | | { |
| | | switch (schemaAttr) |
| | |
| | | for (final Object definition : remainingAttrs) |
| | | { |
| | | final ByteStringBuilder sb = new ByteStringBuilder(); |
| | | sb.append(definition); |
| | | sb.appendObject(definition); |
| | | if (definition.toString().contains(SchemaConstants.OID_OPENDS_SERVER_BASE)) |
| | | { |
| | | try |
| | |
| | | // Encode the attribute. |
| | | final byte[] idBytes = encodeId(id); |
| | | builder.appendBERLength(idBytes.length); |
| | | builder.append(idBytes); |
| | | builder.appendBytes(idBytes); |
| | | builder.appendBERLength(attribute.size()); |
| | | for (final ByteString v : attribute) |
| | | { |
| | | builder.appendBERLength(v.length()); |
| | | builder.append(v); |
| | | builder.appendBytes(v); |
| | | } |
| | | } |
| | | |
| | |
| | | // Encode the object classes. |
| | | final byte[] idBytes = encodeId(id); |
| | | builder.appendBERLength(idBytes.length); |
| | | builder.append(idBytes); |
| | | builder.appendBytes(idBytes); |
| | | } |
| | | |
| | | |
| | |
| | | byte[] vBytes = StaticUtils.getBytes(value); |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | builder.appendBERLength(vBytes.length); |
| | | builder.append(vBytes); |
| | | builder.appendBytes(vBytes); |
| | | return builder.toByteArray(); |
| | | } |
| | | else |
| | |
| | | private byte[] encodeURIAndDN(String labeledURI, DN dn) |
| | | { |
| | | return new ByteStringBuilder() |
| | | .append(labeledURI) |
| | | .append(STRING_SEPARATOR) |
| | | .append(dn.toString()) |
| | | .appendUtf8(labeledURI) |
| | | .appendByte(STRING_SEPARATOR) |
| | | .appendUtf8(dn.toString()) |
| | | .toByteArray(); |
| | | } |
| | | |
| | |
| | | entry.encode(entryBuffer, dataConfig.getEntryEncodeConfig()); |
| | | |
| | | // First write the DB format version byte. |
| | | encodedBuffer.append(JebFormat.FORMAT_VERSION); |
| | | encodedBuffer.appendByte(JebFormat.FORMAT_VERSION); |
| | | |
| | | try |
| | | { |
| | |
| | | int startSize = dn.size() - prefixRDNs - 1; |
| | | for (int i = startSize; i >= 0; i--) |
| | | { |
| | | builder.append(DN.NORMALIZED_RDN_SEPARATOR); |
| | | builder.appendByte(DN.NORMALIZED_RDN_SEPARATOR); |
| | | dn.getRDN(i).toNormalizedByteString(builder); |
| | | } |
| | | |
| | |
| | | final MatchingRule eqRule = types[i].getEqualityMatchingRule(); |
| | | final ByteString nv = eqRule.normalizeAttributeValue(v); |
| | | builder.appendBERLength(nv.length()); |
| | | builder.append(nv); |
| | | builder.appendBytes(nv); |
| | | } |
| | | } |
| | | builder.trimToSize(); |
| | |
| | | final MatchingRule eqRule = types[i].getEqualityMatchingRule(); |
| | | final ByteString nv = eqRule.normalizeAttributeValue(v); |
| | | builder.appendBERLength(nv.length()); |
| | | builder.append(nv); |
| | | builder.appendBytes(nv); |
| | | } |
| | | } |
| | | builder.append(entryID); |
| | | builder.appendLong(entryID); |
| | | builder.trimToSize(); |
| | | |
| | | return builder.getBackingArray(); |
| | |
| | | cursor.delete(); |
| | | |
| | | ByteString newDnKeySuffix = currentDnKey.subSequence(oldTargetDnKeyLength, currentDnKey.length()); |
| | | ByteSequence newDnKey = new ByteStringBuilder(newTargetDnKey).append(newDnKeySuffix); |
| | | ByteSequence newDnKey = new ByteStringBuilder(newTargetDnKey).appendBytes(newDnKeySuffix); |
| | | EntryID newID = renumberEntryIDs ? rootContainer.getNextEntryID() : oldID; |
| | | txn.put(getName(), newDnKey, newID.toByteString()); |
| | | |
| | |
| | | |
| | | private ByteSequence nextSibling() |
| | | { |
| | | return builder.clear().append(delegate.getKey()).append((byte) 0x1); |
| | | return builder.clear().appendBytes(delegate.getKey()).appendByte(0x1); |
| | | } |
| | | } |
| | | |
| | |
| | | // encode the dn inside the value |
| | | // because the dn is encoded in a non reversible way in the key |
| | | byte[] dnBytes = StaticUtils.getBytes(dn.toString()); |
| | | b.append(dnBytes.length); |
| | | b.append(dnBytes); |
| | | b.append(col.size()); |
| | | b.appendInt(dnBytes.length); |
| | | b.appendBytes(dnBytes); |
| | | b.appendInt(col.size()); |
| | | for (String s : col) |
| | | { |
| | | byte[] bytes = StaticUtils.getBytes(s); |
| | | b.append(bytes.length); |
| | | b.append(bytes); |
| | | b.appendInt(bytes.length); |
| | | b.appendBytes(bytes); |
| | | } |
| | | return b; |
| | | } |
| | |
| | | final int startSize = dn.size() - prefixRDNs - 1; |
| | | for (int i = startSize; i >= 0; i--) |
| | | { |
| | | builder.append(DN.NORMALIZED_RDN_SEPARATOR); |
| | | builder.appendByte(DN.NORMALIZED_RDN_SEPARATOR); |
| | | dn.getRDN(i).toNormalizedByteString(builder); |
| | | } |
| | | return builder.toByteString(); |
| | |
| | | static ByteStringBuilder beforeKey(final ByteSequence key) |
| | | { |
| | | final ByteStringBuilder beforeKey = new ByteStringBuilder(key.length() + 1); |
| | | beforeKey.append(key); |
| | | beforeKey.append((byte) 0x00); |
| | | beforeKey.appendBytes(key); |
| | | beforeKey.appendByte(0x00); |
| | | return beforeKey; |
| | | } |
| | | |
| | | static ByteStringBuilder afterKey(final ByteSequence key) |
| | | { |
| | | final ByteStringBuilder afterKey = new ByteStringBuilder(key.length() + 1); |
| | | afterKey.append(key); |
| | | afterKey.append((byte) 0x01); |
| | | afterKey.appendBytes(key); |
| | | afterKey.appendByte(0x01); |
| | | return afterKey; |
| | | } |
| | | } |
| | |
| | | { |
| | | for (long value : idSet.getIDs()) |
| | | { |
| | | builder.append(value); |
| | | builder.appendLong(value); |
| | | } |
| | | return builder; |
| | | } |
| | | // Set top bit. |
| | | return builder.append((byte) 0x80); |
| | | return builder.appendByte(0x80); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | builder.append(UNDEFINED_SET); |
| | | builder.appendByte(UNDEFINED_SET); |
| | | } |
| | | return builder; |
| | | } |
| | |
| | | entry.encode(entryBuffer, dataConfig.getEntryEncodeConfig()); |
| | | |
| | | // First write the DB format version byte. |
| | | encodedBuffer.append(DnKeyFormat.FORMAT_VERSION); |
| | | encodedBuffer.appendByte(DnKeyFormat.FORMAT_VERSION); |
| | | |
| | | try |
| | | { |
| | |
| | | { |
| | | final ByteStringBuilder builder = new ByteStringBuilder(); |
| | | encodeVLVKey0(sortOrder, entry, builder); |
| | | builder.append(entryID); |
| | | builder.appendLong(entryID); |
| | | return builder.toByteString(); |
| | | } |
| | | |
| | |
| | | if ((b & (byte) 0x01) == b) |
| | | { |
| | | // Escape bytes that look like a separator. |
| | | builder.append(escape); |
| | | builder.appendByte(escape); |
| | | } |
| | | else if (i == 0 && (b & (byte) 0xfe) == (byte) 0xfe) |
| | | { |
| | |
| | | * Ensure that all keys sort before (ascending) or after (descending) null keys, by |
| | | * escaping the first byte if it looks like a null key. |
| | | */ |
| | | builder.append((byte) ~escape); |
| | | builder.appendByte(~escape); |
| | | } |
| | | // Invert the bits if this key is in descending order. |
| | | builder.append((byte) (b ^ sortOrderMask)); |
| | | builder.appendByte(b ^ sortOrderMask); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // Ensure that null keys sort after (ascending) or before (descending) all other keys. |
| | | builder.append(ascending ? (byte) 0xff : (byte) 0x00); |
| | | builder.appendByte(ascending ? 0xFF : 0x00); |
| | | } |
| | | builder.append(separator); |
| | | builder.appendByte(separator); |
| | | } |
| | | |
| | | @Override |
| | |
| | | // Append any unused data in the channel buffer to the save buffer |
| | | if(byteBuffer.remaining() > 0) |
| | | { |
| | | saveBuffer.append(byteBuffer, byteBuffer.remaining()); |
| | | saveBuffer.appendBytes(byteBuffer, byteBuffer.remaining()); |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.protocols.ldap; |
| | | |
| | |
| | | // Append any unused data in the channel buffer to the save buffer |
| | | if (byteBuffer.remaining() > 0) |
| | | { |
| | | saveBuffer.append(byteBuffer, byteBuffer.remaining()); |
| | | saveBuffer.appendBytes(byteBuffer, byteBuffer.remaining()); |
| | | } |
| | | |
| | | byteBuffer.clear(); |
| | |
| | | throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message); |
| | | } |
| | | |
| | | valueBuffer.append(byteValue); |
| | | valueBuffer.appendByte(byteValue); |
| | | } |
| | | else |
| | | { |
| | | valueBuffer.append(valueBytes[i]); |
| | | valueBuffer.appendByte(valueBytes[i]); |
| | | } |
| | | } |
| | | |
| | |
| | | throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message); |
| | | } |
| | | |
| | | buffer.append(byteValue); |
| | | buffer.appendByte(byteValue); |
| | | } |
| | | else |
| | | { |
| | | buffer.append(valueBytes[i]); |
| | | buffer.appendByte(valueBytes[i]); |
| | | } |
| | | } |
| | | |
| | |
| | | throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message); |
| | | } |
| | | |
| | | buffer.append(byteValue); |
| | | buffer.appendByte(byteValue); |
| | | } |
| | | else |
| | | { |
| | | buffer.append(valueBytes[i]); |
| | | buffer.appendByte(valueBytes[i]); |
| | | } |
| | | } |
| | | |
| | |
| | | throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message); |
| | | } |
| | | |
| | | buffer.append(byteValue); |
| | | buffer.appendByte(byteValue); |
| | | } |
| | | else |
| | | { |
| | | buffer.append(valueBytes[i]); |
| | | buffer.appendByte(valueBytes[i]); |
| | | } |
| | | } |
| | | |
| | |
| | | throw new LDAPException(LDAPResultCode.PROTOCOL_ERROR, message); |
| | | } |
| | | |
| | | valueBuffer.append(byteValue); |
| | | valueBuffer.appendByte(byteValue); |
| | | } |
| | | else |
| | | { |
| | | valueBuffer.append(valueBytes[i]); |
| | | valueBuffer.appendByte(valueBytes[i]); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | public ByteStringBuilder toByteString(ByteStringBuilder builder) |
| | | { |
| | | return builder.append(timeStamp).append((short) (serverId & 0xffff)) |
| | | .append(seqnum); |
| | | return builder.appendLong(timeStamp).appendShort(serverId & 0xffff).appendInt(seqnum); |
| | | } |
| | | |
| | | /** |
| | |
| | | public String keyToHumanReadableString(ByteSequence key) |
| | | { |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | bsb.append(key.subSequence(2, 10)); |
| | | bsb.append(key.subSequence(0, 2)); |
| | | bsb.append(key.subSequence(10, 14)); |
| | | bsb.appendBytes(key.subSequence(2, 10)); |
| | | bsb.appendBytes(key.subSequence(0, 2)); |
| | | bsb.appendBytes(key.subSequence(10, 14)); |
| | | CSN csn = CSN.valueOf(bsb.toByteString()); |
| | | return csn.toStringUI(); |
| | | } |
| | |
| | | int csnIndex = value.toString().indexOf(':') + 1; |
| | | String csn = value.subSequence(csnIndex, csnIndex + 28).toString(); |
| | | ByteStringBuilder builder = new ByteStringBuilder(14); |
| | | builder.append(hexStringToByteArray(csn.substring(16, 20))); |
| | | builder.append(hexStringToByteArray(csn.substring(0, 16))); |
| | | builder.append(hexStringToByteArray(csn.substring(20, 28))); |
| | | builder.appendBytes(hexStringToByteArray(csn.substring(16, 20))); |
| | | builder.appendBytes(hexStringToByteArray(csn.substring(0, 16))); |
| | | builder.appendBytes(hexStringToByteArray(csn.substring(20, 28))); |
| | | return builder.toByteString(); |
| | | } |
| | | catch (Exception e) |
| | |
| | | public void addAttribute(String name, String value) throws DecodeException |
| | | { |
| | | ByteStringBuilder byteBuilder = new ByteStringBuilder(); |
| | | byteBuilder.append(encodedAttributes); |
| | | byteBuilder.appendBytes(encodedAttributes); |
| | | |
| | | ASN1Writer writer = ASN1.getWriter(byteBuilder); |
| | | |
| | |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2014 ForgeRock AS |
| | | * Copyright 2014-2015 ForgeRock AS |
| | | */ |
| | | package org.opends.server.replication.protocol; |
| | | |
| | |
| | | */ |
| | | public ByteArrayBuilder appendBoolean(boolean b) |
| | | { |
| | | appendByte((byte) (b ? 1 : 0)); |
| | | appendByte(b ? 1 : 0); |
| | | return this; |
| | | } |
| | | |
| | |
| | | * the byte to append. |
| | | * @return this ByteArrayBuilder |
| | | */ |
| | | public ByteArrayBuilder appendByte(byte b) |
| | | public ByteArrayBuilder appendByte(int b) |
| | | { |
| | | builder.append(b); |
| | | builder.appendByte(b); |
| | | return this; |
| | | } |
| | | |
| | |
| | | * the short to append. |
| | | * @return this ByteArrayBuilder |
| | | */ |
| | | public ByteArrayBuilder appendShort(short s) |
| | | public ByteArrayBuilder appendShort(int s) |
| | | { |
| | | builder.append(s); |
| | | builder.appendShort(s); |
| | | return this; |
| | | } |
| | | |
| | |
| | | */ |
| | | public ByteArrayBuilder appendInt(int i) |
| | | { |
| | | builder.append(i); |
| | | builder.appendInt(i); |
| | | return this; |
| | | } |
| | | |
| | |
| | | */ |
| | | public ByteArrayBuilder appendLong(long l) |
| | | { |
| | | builder.append(l); |
| | | builder.appendLong(l); |
| | | return this; |
| | | } |
| | | |
| | |
| | | public ByteArrayBuilder appendStrings(Collection<String> col) |
| | | { |
| | | //appendInt() would have been safer, but byte is compatible with legacy code |
| | | appendByte((byte) col.size()); |
| | | appendByte(col.size()); |
| | | for (String s : col) |
| | | { |
| | | appendString(s); |
| | |
| | | */ |
| | | public ByteArrayBuilder appendByteArray(byte[] bytes) |
| | | { |
| | | builder.append(bytes); |
| | | builder.appendBytes(bytes); |
| | | return this; |
| | | } |
| | | |
| | |
| | | */ |
| | | public ByteArrayBuilder appendZeroTerminatedByteArray(byte[] bytes) |
| | | { |
| | | builder.append(bytes); |
| | | builder.appendBytes(bytes); |
| | | return appendZeroSeparator(); |
| | | } |
| | | |
| | | private ByteArrayBuilder appendZeroSeparator() |
| | | { |
| | | builder.append((byte) 0); |
| | | builder.appendByte(0); |
| | | return this; |
| | | } |
| | | |
| | |
| | | */ |
| | | final ByteArrayBuilder builder = new ByteArrayBuilder(); |
| | | builder.appendByte(msgType); |
| | | builder.appendByte((byte) protocolVersion); |
| | | builder.appendByte(protocolVersion); |
| | | builder.appendCSNUTF8(csn); |
| | | builder.appendDN(dn); |
| | | builder.appendString(entryUUID); |
| | |
| | | if (protocolVersion == ProtocolVersion.REPLICATION_PROTOCOL_V1) |
| | | { |
| | | // legacy coding mistake |
| | | builder.appendByte((byte) 0); |
| | | builder.appendByte(0); |
| | | } |
| | | return builder.toByteArray(); |
| | | } |
| | |
| | | } |
| | | else if (protocolVersion <= ProtocolVersion.REPLICATION_PROTOCOL_V3) |
| | | { |
| | | builder.appendShort((short) data); |
| | | builder.appendShort(data); |
| | | } |
| | | else // protocolVersion >= ProtocolVersion.REPLICATION_PROTOCOL_V4 |
| | | { |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | * Portions Copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.replication.protocol; |
| | | |
| | |
| | | * <message type><protocol version><generation id><group id> |
| | | */ |
| | | builder.appendByte(msgType); |
| | | builder.appendByte((byte) protocolVersion); |
| | | builder.appendByte(protocolVersion); |
| | | builder.appendLongUTF8(generationId); |
| | | builder.appendByte(groupId); |
| | | } |
| | |
| | | * <message type><protocol version><generation id> |
| | | */ |
| | | builder.appendByte(msgType); |
| | | builder.appendByte((byte) ProtocolVersion.REPLICATION_PROTOCOL_V1_REAL); |
| | | builder.appendByte((byte) 0); |
| | | builder.appendByte(ProtocolVersion.REPLICATION_PROTOCOL_V1_REAL); |
| | | builder.appendByte(0); |
| | | builder.appendLongUTF8(generationId); |
| | | } |
| | | |
| | |
| | | ByteStringBuilder byteBuilder = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(byteBuilder); |
| | | |
| | | byteBuilder.append(MSG_TYPE_START_SESSION); |
| | | byteBuilder.append(status.getValue()); |
| | | byteBuilder.append(assuredFlag ? (byte) 1 : (byte) 0); |
| | | byteBuilder.append(assuredMode.getValue()); |
| | | byteBuilder.append(safeDataLevel); |
| | | byteBuilder.appendByte(MSG_TYPE_START_SESSION); |
| | | byteBuilder.appendByte(status.getValue()); |
| | | byteBuilder.appendByte(assuredFlag ? 1 : 0); |
| | | byteBuilder.appendByte(assuredMode.getValue()); |
| | | byteBuilder.appendByte(safeDataLevel); |
| | | |
| | | writer.writeStartSequence(); |
| | | for (String url : referralsURLs) |
| | |
| | | builder.appendByte(MSG_TYPE_TOPOLOGY); |
| | | |
| | | // Put DS infos |
| | | builder.appendByte((byte) replicaInfos.size()); |
| | | builder.appendByte(replicaInfos.size()); |
| | | for (DSInfo dsInfo : replicaInfos.values()) |
| | | { |
| | | builder.appendIntUTF8(dsInfo.getDsId()); |
| | |
| | | { |
| | | builder.appendStrings(dsInfo.getEclIncludesForDeletes()); |
| | | } |
| | | builder.appendByte((byte) dsInfo.getProtocolVersion()); |
| | | builder.appendByte(dsInfo.getProtocolVersion()); |
| | | } |
| | | } |
| | | |
| | | // Put RS infos |
| | | builder.appendByte((byte) rsInfos.size()); |
| | | builder.appendByte(rsInfos.size()); |
| | | for (RSInfo rsInfo : rsInfos) |
| | | { |
| | | builder.appendIntUTF8(rsInfo.getId()); |
| | |
| | | */ |
| | | protected ByteArrayBuilder encodeHeader(byte msgType, short protocolVersion) |
| | | { |
| | | final ByteArrayBuilder builder = |
| | | new ByteArrayBuilder(bytes(6) + csnsUTF8(1)); |
| | | final ByteArrayBuilder builder = new ByteArrayBuilder(bytes(6) + csnsUTF8(1)); |
| | | builder.appendByte(msgType); |
| | | builder.appendByte((byte) ProtocolVersion.getCurrentVersion()); |
| | | builder.appendByte(ProtocolVersion.getCurrentVersion()); |
| | | builder.appendCSNUTF8(getCSN()); |
| | | builder.appendBoolean(assuredFlag); |
| | | builder.appendByte(assuredMode.getValue()); |
| | |
| | | { |
| | | if (distanceToBlockStart != 0) |
| | | { |
| | | recordBytes.append(reader, distanceToBlockStart); |
| | | recordBytes.appendBytes(reader, distanceToBlockStart); |
| | | } |
| | | // skip the offset |
| | | reader.skipBytes(SIZE_OF_BLOCK_OFFSET); |
| | |
| | | if (remainingBytesToRead > 0) |
| | | { |
| | | // last bytes of the record |
| | | recordBytes.append(reader, remainingBytesToRead); |
| | | recordBytes.appendBytes(reader, remainingBytesToRead); |
| | | } |
| | | return recordBytes.toByteString(); |
| | | } |
| | |
| | | final ByteStringBuilder lengthBytes = new ByteStringBuilder(SIZE_OF_RECORD_SIZE); |
| | | if (distanceToBlockStart > 0 && distanceToBlockStart < SIZE_OF_RECORD_SIZE) |
| | | { |
| | | lengthBytes.append(reader, distanceToBlockStart); |
| | | lengthBytes.appendBytes(reader, distanceToBlockStart); |
| | | // skip the offset |
| | | reader.skipBytes(SIZE_OF_BLOCK_OFFSET); |
| | | lengthBytes.append(reader, SIZE_OF_RECORD_SIZE - distanceToBlockStart); |
| | | lengthBytes.appendBytes(reader, SIZE_OF_RECORD_SIZE - distanceToBlockStart); |
| | | } |
| | | else |
| | | { |
| | |
| | | // skip the offset |
| | | reader.skipBytes(SIZE_OF_BLOCK_OFFSET); |
| | | } |
| | | lengthBytes.append(reader, SIZE_OF_RECORD_SIZE); |
| | | lengthBytes.appendBytes(reader, SIZE_OF_RECORD_SIZE); |
| | | } |
| | | return lengthBytes.toByteString().toInt(); |
| | | } |
| | |
| | | { |
| | | // Add length of record before writing |
| | | ByteString data = new ByteStringBuilder(SIZE_OF_RECORD_SIZE + record.length()). |
| | | append(record.length()). |
| | | append(record). |
| | | appendInt(record.length()). |
| | | appendBytes(record). |
| | | toByteString(); |
| | | |
| | | int distanceToBlockStart = BlockLogReader.getDistanceToNextBlockStart(writer.getBytesWritten(), blockSize); |
| | |
| | | { |
| | | final ChangeNumberIndexRecord cnIndexRecord = record.getValue(); |
| | | return new ByteStringBuilder() |
| | | .append((long) record.getKey()) |
| | | .append(cnIndexRecord.getBaseDN().toString()) |
| | | .append(STRING_SEPARATOR) |
| | | .append(cnIndexRecord.getCSN().toByteString()).toByteString(); |
| | | .appendLong(record.getKey()) |
| | | .appendUtf8(cnIndexRecord.getBaseDN().toString()) |
| | | .appendByte(STRING_SEPARATOR) |
| | | .appendBytes(cnIndexRecord.getCSN().toByteString()) |
| | | .toByteString(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2015 ForgeRock AS |
| | | */ |
| | | package org.opends.server.tools.upgrade; |
| | | |
| | |
| | | int length = dnString.length(); |
| | | if (pos >= length) |
| | | { |
| | | attributeValue.append(""); |
| | | attributeValue.appendUtf8(""); |
| | | return pos; |
| | | } |
| | | |
| | |
| | | // octet string. |
| | | try |
| | | { |
| | | attributeValue.append( |
| | | hexStringToByteArray(hexString.toString())); |
| | | attributeValue.appendBytes(hexStringToByteArray(hexString.toString())); |
| | | return pos; |
| | | } |
| | | catch (Exception e) |
| | |
| | | // should continue until the corresponding closing quotation mark. |
| | | else if (c == '"') |
| | | { |
| | | // Keep reading until we find an unescaped closing quotation |
| | | // mark. |
| | | // Keep reading until we find an unescaped closing quotation mark. |
| | | boolean escaped = false; |
| | | StringBuilder valueString = new StringBuilder(); |
| | | while (true) |
| | |
| | | } |
| | | } |
| | | |
| | | attributeValue.append(valueString.toString()); |
| | | attributeValue.appendUtf8(valueString.toString()); |
| | | return pos; |
| | | } |
| | | else if(c == '+' || c == ',') |
| | |
| | | } |
| | | |
| | | |
| | | attributeValue.append(valueString.toString()); |
| | | attributeValue.appendUtf8(valueString.toString()); |
| | | return pos; |
| | | } |
| | | } |
| | |
| | | rdnComponents[numComponents - 1].toNormalizedByteString(builder); |
| | | for (int i = numComponents - 2; i >= 0; i--) |
| | | { |
| | | builder.append(NORMALIZED_RDN_SEPARATOR); |
| | | builder.appendByte(NORMALIZED_RDN_SEPARATOR); |
| | | rdnComponents[i].toNormalizedByteString(builder); |
| | | } |
| | | normalizedDN = builder.toByteString(); |
| | |
| | | throws DirectoryException |
| | | { |
| | | // The version number will be one byte. |
| | | buffer.append((byte)0x03); |
| | | buffer.appendByte(0x03); |
| | | |
| | | // Get the encoded representation of the config. |
| | | config.encode(buffer); |
| | |
| | | // TODO: Can we encode the DN directly into buffer? |
| | | byte[] dnBytes = getBytes(dn.toString()); |
| | | buffer.appendBERLength(dnBytes.length); |
| | | buffer.append(dnBytes); |
| | | buffer.appendBytes(dnBytes); |
| | | } |
| | | |
| | | |
| | |
| | | buffer.appendBERLength(objectClasses.size()); |
| | | for (String ocName : objectClasses.values()) |
| | | { |
| | | buffer.append(ocName); |
| | | buffer.append((byte)0x00); |
| | | buffer.appendUtf8(ocName); |
| | | buffer.appendByte(0x00); |
| | | } |
| | | } |
| | | |
| | |
| | | for (Attribute a : attrList) |
| | | { |
| | | byte[] nameBytes = getBytes(a.getNameWithOptions()); |
| | | buffer.append(nameBytes); |
| | | buffer.append((byte)0x00); |
| | | buffer.appendBytes(nameBytes); |
| | | buffer.appendByte(0x00); |
| | | |
| | | buffer.appendBERLength(a.size()); |
| | | for(ByteString v : a) |
| | | { |
| | | buffer.appendBERLength(v.length()); |
| | | buffer.append(v); |
| | | buffer.appendBytes(v); |
| | | } |
| | | } |
| | | } |
| | |
| | | public void encode(ByteStringBuilder buffer) |
| | | { |
| | | buffer.appendBERLength(1); |
| | | buffer.append(encodedRepresentation); |
| | | buffer.appendByte(encodedRepresentation); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | if (normalizedRDN != null) |
| | | { |
| | | return builder.append(normalizedRDN); |
| | | return builder.appendBytes(normalizedRDN); |
| | | } |
| | | return computeNormalizedByteString(builder); |
| | | } |
| | |
| | | } |
| | | |
| | | Iterator<ByteString> iterator = avaStrings.iterator(); |
| | | builder.append(iterator.next()); |
| | | builder.appendBytes(iterator.next()); |
| | | while (iterator.hasNext()) |
| | | { |
| | | builder.append(DN.NORMALIZED_AVA_SEPARATOR); |
| | | builder.append(iterator.next()); |
| | | builder.appendByte(DN.NORMALIZED_AVA_SEPARATOR); |
| | | builder.appendBytes(iterator.next()); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | private ByteStringBuilder normalizeAVAToByteString(int position, final ByteStringBuilder builder) |
| | | { |
| | | builder.append(attributeTypes[position].getNormalizedPrimaryNameOrOID()); |
| | | builder.append("="); |
| | | builder.appendUtf8(attributeTypes[position].getNormalizedPrimaryNameOrOID()); |
| | | builder.appendUtf8("="); |
| | | final ByteString value = getEqualityNormalizedValue(position); |
| | | if (value.length() > 0) |
| | | { |
| | | builder.append(escapeBytes(value)); |
| | | builder.appendBytes(escapeBytes(value)); |
| | | } |
| | | return builder; |
| | | } |
| | |
| | | final byte b = value.byteAt(i); |
| | | if (isByteToEscape(b)) |
| | | { |
| | | builder.append(DN.NORMALIZED_ESC_BYTE); |
| | | builder.appendByte(DN.NORMALIZED_ESC_BYTE); |
| | | } |
| | | builder.append(b); |
| | | builder.appendByte(b); |
| | | } |
| | | return builder.toByteString(); |
| | | } |
| | |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int read() throws IOException { |
| | | int readByte = parentStream.read(); |
| | | if(enableRecording) |
| | | { |
| | | buffer.append((byte)readByte); |
| | | buffer.appendByte(readByte); |
| | | } |
| | | return readByte; |
| | | } |
| | |
| | | int bytesRead = parentStream.read(bytes); |
| | | if(enableRecording) |
| | | { |
| | | buffer.append(bytes, 0, bytesRead); |
| | | buffer.appendBytes(bytes, 0, bytesRead); |
| | | } |
| | | return bytesRead; |
| | | } |
| | |
| | | int bytesRead = parentStream.read(bytes, i, i1); |
| | | if(enableRecording) |
| | | { |
| | | buffer.append(bytes, i, bytesRead); |
| | | buffer.appendBytes(bytes, i, bytesRead); |
| | | } |
| | | return bytesRead; |
| | | } |
| | |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void write(int i) throws IOException { |
| | | if(enableRecording) |
| | | { |
| | | buffer.append((byte) i); |
| | | buffer.appendByte(i); |
| | | } |
| | | parentStream.write(i); |
| | | } |
| | |
| | | public void write(byte[] bytes) throws IOException { |
| | | if(enableRecording) |
| | | { |
| | | buffer.append(bytes); |
| | | buffer.appendBytes(bytes); |
| | | } |
| | | parentStream.write(bytes); |
| | | } |
| | |
| | | public void write(byte[] bytes, int i, int i1) throws IOException { |
| | | if(enableRecording) |
| | | { |
| | | buffer.append(bytes, i, i1); |
| | | buffer.appendBytes(bytes, i, i1); |
| | | } |
| | | parentStream.write(bytes, i, i1); |
| | | } |
| | |
| | | ResultCode.PROTOCOL_ERROR, message); |
| | | } |
| | | |
| | | valueBuffer.append(byteValue); |
| | | valueBuffer.appendByte(byteValue); |
| | | } |
| | | else |
| | | { |
| | | valueBuffer.append(valueBytes[i]); |
| | | valueBuffer.appendByte(valueBytes[i]); |
| | | } |
| | | } |
| | | |
| | |
| | | ResultCode.PROTOCOL_ERROR, message); |
| | | } |
| | | |
| | | buffer.append(byteValue); |
| | | buffer.appendByte(byteValue); |
| | | } |
| | | else |
| | | { |
| | | buffer.append(valueBytes[i]); |
| | | buffer.appendByte(valueBytes[i]); |
| | | } |
| | | } |
| | | |
| | |
| | | ResultCode.PROTOCOL_ERROR, message); |
| | | } |
| | | |
| | | buffer.append(byteValue); |
| | | buffer.appendByte(byteValue); |
| | | } |
| | | else |
| | | { |
| | | buffer.append(valueBytes[i]); |
| | | buffer.appendByte(valueBytes[i]); |
| | | } |
| | | } |
| | | |
| | |
| | | ResultCode.PROTOCOL_ERROR, message); |
| | | } |
| | | |
| | | buffer.append(byteValue); |
| | | buffer.appendByte(byteValue); |
| | | } |
| | | else |
| | | { |
| | | buffer.append(valueBytes[i]); |
| | | buffer.appendByte(valueBytes[i]); |
| | | } |
| | | } |
| | | |
| | |
| | | message); |
| | | } |
| | | |
| | | valueBuffer.append(byteValue); |
| | | valueBuffer.appendByte(byteValue); |
| | | } |
| | | else |
| | | { |
| | | valueBuffer.append(valueBytes[i]); |
| | | valueBuffer.appendByte(valueBytes[i]); |
| | | } |
| | | } |
| | | |
| | |
| | | ByteStringBuilder builder = new ByteStringBuilder(4096); |
| | | inputStream = contentURL.openConnection().getInputStream(); |
| | | |
| | | while (builder.append(inputStream, 4096) != -1) { /* Do nothing */ } |
| | | while (builder.appendBytes(inputStream, 4096) != -1) { /* Do nothing */ } |
| | | |
| | | value = builder.toByteString(); |
| | | } |
| | |
| | | if (p.waitFor() != 0) { |
| | | ByteStringBuilder stdOut = new ByteStringBuilder(); |
| | | ByteStringBuilder stdErr = new ByteStringBuilder(); |
| | | while(stdOut.append(p.getInputStream(), 512) > 0) {} |
| | | while(stdErr.append(p.getErrorStream(), 512) > 0) {} |
| | | while(stdOut.appendBytes(p.getInputStream(), 512) > 0) {} |
| | | while(stdErr.appendBytes(p.getErrorStream(), 512) > 0) {} |
| | | throw new IllegalStateException( |
| | | "setup server process failed:\n" + |
| | | "exit value: " + p.exitValue() + "\n" + |
| | |
| | | .getRootConnection(); |
| | | |
| | | ByteStringBuilder credentials = new ByteStringBuilder(); |
| | | credentials.append((byte) 0); |
| | | credentials.append("dn:" + userDNString); |
| | | credentials.append((byte) 0); |
| | | credentials.append("password"); |
| | | credentials.appendByte(0); |
| | | credentials.appendUtf8("dn:" + userDNString); |
| | | credentials.appendByte(0); |
| | | credentials.appendUtf8("password"); |
| | | |
| | | BindOperation bind = conn.processSASLBind(DN.rootDN(), "PLAIN", |
| | | credentials.toByteString()); |
| | |
| | | throws DirectoryException |
| | | { |
| | | // The version number will be one byte. |
| | | buffer.append((byte)0x01); |
| | | buffer.appendByte(0x01); |
| | | |
| | | // TODO: Can we encode the DN directly into buffer? |
| | | byte[] dnBytes = getBytes(entry.getName().toString()); |
| | | buffer.appendBERLength(dnBytes.length); |
| | | buffer.append(dnBytes); |
| | | buffer.appendBytes(dnBytes); |
| | | |
| | | |
| | | // Encode number of OCs and 0 terminated names. |
| | |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | for (String ocName : entry.getObjectClasses().values()) |
| | | { |
| | | bsb.append(ocName); |
| | | bsb.appendUtf8(ocName); |
| | | if(i < entry.getObjectClasses().values().size()) |
| | | { |
| | | bsb.append((byte)0x00); |
| | | bsb.appendByte(0x00); |
| | | } |
| | | i++; |
| | | } |
| | | buffer.appendBERLength(bsb.length()); |
| | | buffer.append(bsb); |
| | | buffer.appendBytes(bsb); |
| | | |
| | | |
| | | // Encode the user attributes in the appropriate manner. |
| | |
| | | throws DirectoryException |
| | | { |
| | | // The version number will be one byte. |
| | | buffer.append((byte)0x02); |
| | | buffer.appendByte(0x02); |
| | | |
| | | // Get the encoded respresentation of the config. |
| | | config.encode(buffer); |
| | |
| | | // TODO: Can we encode the DN directly into buffer? |
| | | byte[] dnBytes = getBytes(entry.getName().toString()); |
| | | buffer.appendBERLength(dnBytes.length); |
| | | buffer.append(dnBytes); |
| | | buffer.appendBytes(dnBytes); |
| | | } |
| | | |
| | | |
| | |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | for (String ocName : entry.getObjectClasses().values()) |
| | | { |
| | | bsb.append(ocName); |
| | | bsb.appendUtf8(ocName); |
| | | if(i < entry.getObjectClasses().values().size()) |
| | | { |
| | | bsb.append((byte)0x00); |
| | | bsb.appendByte(0x00); |
| | | } |
| | | i++; |
| | | } |
| | | buffer.appendBERLength(bsb.length()); |
| | | buffer.append(bsb); |
| | | buffer.appendBytes(bsb); |
| | | } |
| | | |
| | | |
| | |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | config.getCompressedSchema().encodeAttribute(bsb, a); |
| | | buffer.appendBERLength(bsb.length()); |
| | | buffer.append(bsb); |
| | | buffer.appendBytes(bsb); |
| | | } |
| | | } |
| | | } |
| | |
| | | for (Attribute a : attrList) |
| | | { |
| | | byte[] nameBytes = getBytes(a.getNameWithOptions()); |
| | | buffer.append(nameBytes); |
| | | buffer.append((byte)0x00); |
| | | buffer.appendBytes(nameBytes); |
| | | buffer.appendByte(0x00); |
| | | |
| | | buffer.appendBERLength(a.size()); |
| | | for (ByteString v : a) |
| | | { |
| | | buffer.appendBERLength(v.length()); |
| | | buffer.append(v); |
| | | buffer.appendBytes(v); |
| | | } |
| | | } |
| | | } |
| | |
| | | Collections.sort(resultContainer); |
| | | for (ByteString s : resultContainer) |
| | | { |
| | | builder.append(s); |
| | | builder.append(new char[] { '-' }); |
| | | builder.appendBytes(s); |
| | | builder.appendUtf8(new char[] { '-' }); |
| | | } |
| | | builder.setLength(builder.length() - 1); |
| | | return builder.toByteString(); |
| | |
| | | throws DirectoryException |
| | | { |
| | | // The version number will be one byte. |
| | | buffer.append((byte)0x01); |
| | | buffer.appendByte(0x01); |
| | | |
| | | // TODO: Can we encode the DN directly into buffer? |
| | | byte[] dnBytes = getBytes(entry.getName().toString()); |
| | | buffer.appendBERLength(dnBytes.length); |
| | | buffer.append(dnBytes); |
| | | buffer.appendBytes(dnBytes); |
| | | |
| | | |
| | | // Encode number of OCs and 0 terminated names. |
| | |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | for (String ocName : entry.getObjectClasses().values()) |
| | | { |
| | | bsb.append(ocName); |
| | | bsb.appendUtf8(ocName); |
| | | if(i < entry.getObjectClasses().values().size()) |
| | | { |
| | | bsb.append((byte)0x00); |
| | | bsb.appendByte(0x00); |
| | | } |
| | | i++; |
| | | } |
| | | buffer.appendBERLength(bsb.length()); |
| | | buffer.append(bsb); |
| | | buffer.appendBytes(bsb); |
| | | |
| | | |
| | | // Encode the user attributes in the appropriate manner. |
| | |
| | | throws DirectoryException |
| | | { |
| | | // The version number will be one byte. |
| | | buffer.append((byte)0x02); |
| | | buffer.appendByte(0x02); |
| | | |
| | | // Get the encoded respresentation of the config. |
| | | config.encode(buffer); |
| | |
| | | // TODO: Can we encode the DN directly into buffer? |
| | | byte[] dnBytes = getBytes(entry.getName().toString()); |
| | | buffer.appendBERLength(dnBytes.length); |
| | | buffer.append(dnBytes); |
| | | buffer.appendBytes(dnBytes); |
| | | } |
| | | |
| | | |
| | |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | for (String ocName : entry.getObjectClasses().values()) |
| | | { |
| | | bsb.append(ocName); |
| | | bsb.appendUtf8(ocName); |
| | | if(i < entry.getObjectClasses().values().size()) |
| | | { |
| | | bsb.append((byte)0x00); |
| | | bsb.appendByte(0x00); |
| | | } |
| | | i++; |
| | | } |
| | | buffer.appendBERLength(bsb.length()); |
| | | buffer.append(bsb); |
| | | buffer.appendBytes(bsb); |
| | | } |
| | | |
| | | |
| | |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | config.getCompressedSchema().encodeAttribute(bsb, a); |
| | | buffer.appendBERLength(bsb.length()); |
| | | buffer.append(bsb); |
| | | buffer.appendBytes(bsb); |
| | | } |
| | | } |
| | | } |
| | |
| | | for (Attribute a : attrList) |
| | | { |
| | | byte[] nameBytes = getBytes(a.getNameWithOptions()); |
| | | buffer.append(nameBytes); |
| | | buffer.append((byte)0x00); |
| | | buffer.appendBytes(nameBytes); |
| | | buffer.appendByte(0x00); |
| | | |
| | | buffer.appendBERLength(a.size()); |
| | | for (ByteString v : a) |
| | | { |
| | | buffer.appendBERLength(v.length()); |
| | | buffer.append(v); |
| | | buffer.appendBytes(v); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | ByteStringBuilder saslCredBytes = new ByteStringBuilder(); |
| | | saslCredBytes.append((byte)0); |
| | | saslCredBytes.append("test.user"); |
| | | saslCredBytes.append((byte)0); |
| | | saslCredBytes.append(password); |
| | | saslCredBytes.appendByte(0); |
| | | saslCredBytes.appendUtf8("test.user"); |
| | | saslCredBytes.appendByte(0); |
| | | saslCredBytes.appendBytes(password); |
| | | InternalClientConnection anonymousConn = |
| | | new InternalClientConnection(new AuthenticationInfo()); |
| | | BindOperation bindOperation = |
| | |
| | | |
| | | |
| | | ByteStringBuilder saslCredBytes = new ByteStringBuilder(); |
| | | saslCredBytes.append((byte)0); |
| | | saslCredBytes.append("u:test.user"); |
| | | saslCredBytes.append((byte)0); |
| | | saslCredBytes.append(password); |
| | | saslCredBytes.appendByte(0); |
| | | saslCredBytes.appendUtf8("u:test.user"); |
| | | saslCredBytes.appendByte(0); |
| | | saslCredBytes.appendBytes(password); |
| | | InternalClientConnection anonymousConn = |
| | | new InternalClientConnection(new AuthenticationInfo()); |
| | | BindOperation bindOperation = |
| | |
| | | |
| | | |
| | | ByteStringBuilder saslCredBytes = new ByteStringBuilder(); |
| | | saslCredBytes.append("u:test.user"); |
| | | saslCredBytes.append((byte)0); |
| | | saslCredBytes.append("u:test.user"); |
| | | saslCredBytes.append((byte)0); |
| | | saslCredBytes.append(password); |
| | | saslCredBytes.appendUtf8("u:test.user"); |
| | | saslCredBytes.appendByte(0); |
| | | saslCredBytes.appendUtf8("u:test.user"); |
| | | saslCredBytes.appendByte(0); |
| | | saslCredBytes.appendBytes(password); |
| | | InternalClientConnection anonymousConn = |
| | | new InternalClientConnection(new AuthenticationInfo()); |
| | | BindOperation bindOperation = |
| | |
| | | |
| | | |
| | | ByteStringBuilder saslCredBytes = new ByteStringBuilder(); |
| | | saslCredBytes.append((byte)0); |
| | | saslCredBytes.append("dn:"); |
| | | saslCredBytes.append(e.getName().toString()); |
| | | saslCredBytes.append((byte)0); |
| | | saslCredBytes.append(password); |
| | | saslCredBytes.appendByte(0); |
| | | saslCredBytes.appendUtf8("dn:"); |
| | | saslCredBytes.appendUtf8(e.getName().toString()); |
| | | saslCredBytes.appendByte(0); |
| | | saslCredBytes.appendBytes(password); |
| | | InternalClientConnection anonymousConn = |
| | | new InternalClientConnection(new AuthenticationInfo()); |
| | | BindOperation bindOperation = |
| | |
| | | |
| | | |
| | | ByteStringBuilder saslCredBytes = new ByteStringBuilder(); |
| | | saslCredBytes.append("dn:"); |
| | | saslCredBytes.append(e.getName().toString()); |
| | | saslCredBytes.append((byte)0); |
| | | saslCredBytes.append("dn:"); |
| | | saslCredBytes.append(e.getName().toString()); |
| | | saslCredBytes.append((byte)0); |
| | | saslCredBytes.append(password); |
| | | saslCredBytes.appendUtf8("dn:"); |
| | | saslCredBytes.appendUtf8(e.getName().toString()); |
| | | saslCredBytes.appendByte(0); |
| | | saslCredBytes.appendUtf8("dn:"); |
| | | saslCredBytes.appendUtf8(e.getName().toString()); |
| | | saslCredBytes.appendByte(0); |
| | | saslCredBytes.appendBytes(password); |
| | | InternalClientConnection anonymousConn = |
| | | new InternalClientConnection(new AuthenticationInfo()); |
| | | BindOperation bindOperation = |
| | |
| | | throws Exception |
| | | { |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE); |
| | | bsb.appendByte(ASN1.UNIVERSAL_OCTET_STRING_TYPE); |
| | | bsb.appendBERLength(b.length); |
| | | bsb.append(b); |
| | | bsb.appendBytes(b); |
| | | |
| | | assertEquals(getReader(bsb.toByteArray(), 0).readOctetString(), |
| | | ByteString.wrap(b)); |
| | |
| | | throws Exception |
| | | { |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE); |
| | | bsb.appendByte(ASN1.UNIVERSAL_OCTET_STRING_TYPE); |
| | | bsb.appendBERLength(b.length); |
| | | bsb.append(b); |
| | | bsb.appendBytes(b); |
| | | |
| | | assertEquals(getReader(bsb.toByteArray(), 0).readOctetStringAsString(), |
| | | new String(b, "UTF-8")); |
| | |
| | | throws Exception |
| | | { |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE); |
| | | bsb.appendByte(ASN1.UNIVERSAL_OCTET_STRING_TYPE); |
| | | bsb.appendBERLength(b.length); |
| | | bsb.append(b); |
| | | bsb.appendBytes(b); |
| | | |
| | | ByteStringBuilder bsb2 = new ByteStringBuilder(); |
| | | getReader(bsb.toByteArray(), 0).readOctetString(bsb2); |
| | |
| | | throws Exception |
| | | { |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | bsb.append(ASN1.UNIVERSAL_SEQUENCE_TYPE); |
| | | bsb.appendByte(ASN1.UNIVERSAL_SEQUENCE_TYPE); |
| | | bsb.appendBERLength(encodedElements.length + 2); |
| | | bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE); |
| | | bsb.appendByte(ASN1.UNIVERSAL_OCTET_STRING_TYPE); |
| | | bsb.appendBERLength(encodedElements.length); |
| | | bsb.append(encodedElements); |
| | | bsb.appendBytes(encodedElements); |
| | | |
| | | ASN1Reader reader = getReader(bsb.toByteArray(), 0); |
| | | assertEquals(reader.peekLength(), encodedElements.length + 2); |
| | |
| | | @Override |
| | | public ByteString encodeRecord(Record<Integer, Integer> record) |
| | | { |
| | | return new ByteStringBuilder().append((int) record.getKey()).append((int) record.getValue()).toByteString(); |
| | | return new ByteStringBuilder().appendInt(record.getKey()).appendInt(record.getValue()).toByteString(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | private static final File TEST_DIRECTORY = new File(TestCaseUtils.getUnitTestRootPath(), "changelog-unit"); |
| | | private static final File TEST_LOG_FILE = new File(TEST_DIRECTORY, Log.HEAD_LOG_FILE_NAME); |
| | | static final StringRecordParser RECORD_PARSER = new StringRecordParser(); |
| | | private static final byte STRING_SEPARATOR = 0; |
| | | |
| | | @BeforeClass |
| | | public void createTestDirectory() |
| | |
| | | return new Object[][] |
| | | { |
| | | // write partial record size (should be 4 bytes) |
| | | { 1, new ByteStringBuilder().append((byte) 0) }, |
| | | { 1, new ByteStringBuilder().appendByte(0) }, |
| | | // write partial record size (should be 4 bytes) |
| | | { 2, new ByteStringBuilder().append((byte) 0).append((byte) 0).append((byte) 0) }, |
| | | { 2, new ByteStringBuilder().appendByte(0).appendByte(0).appendByte(0) }, |
| | | // write size only |
| | | { 3, new ByteStringBuilder().append(10) }, |
| | | { 3, new ByteStringBuilder().appendInt(10) }, |
| | | // write size + key |
| | | { 4, new ByteStringBuilder().append(100).append("key") }, |
| | | { 4, new ByteStringBuilder().appendInt(100).appendUtf8("key") }, |
| | | // write size + key + separator |
| | | { 5, new ByteStringBuilder().append(100).append("key").append(StringRecordParser.STRING_SEPARATOR) }, |
| | | { 5, new ByteStringBuilder().appendInt(100).appendUtf8("key").appendByte(STRING_SEPARATOR) }, |
| | | // write size + key + separator + partial value |
| | | { 6, new ByteStringBuilder().append(100).append("key").append(StringRecordParser.STRING_SEPARATOR).append("v") }, |
| | | { 6, new ByteStringBuilder().appendInt(100).appendUtf8("key").appendByte(STRING_SEPARATOR).appendUtf8("v") }, |
| | | }; |
| | | } |
| | | |
| | |
| | | */ |
| | | private static class StringRecordParser implements RecordParser<String, String> |
| | | { |
| | | private static final byte STRING_SEPARATOR = 0; |
| | | |
| | | @Override |
| | | public Record<String, String> decodeRecord(final ByteString data) throws DecodingException |
| | | { |
| | |
| | | public ByteString encodeRecord(Record<String, String> record) |
| | | { |
| | | return new ByteStringBuilder() |
| | | .append(record.getKey()).append(STRING_SEPARATOR) |
| | | .append(record.getValue()).append(STRING_SEPARATOR).toByteString(); |
| | | .appendUtf8(record.getKey()).appendByte(STRING_SEPARATOR) |
| | | .appendUtf8(record.getValue()).appendByte(STRING_SEPARATOR).toByteString(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | DN dn = DN.valueOf("dc=example,dc=com"); |
| | | |
| | | assertEquals(dn.toNormalizedByteString(), |
| | | new ByteStringBuilder().append("dc=com").append(DN.NORMALIZED_RDN_SEPARATOR) |
| | | .append("dc=example").toByteString()); |
| | | new ByteStringBuilder().appendUtf8("dc=com").appendByte(DN.NORMALIZED_RDN_SEPARATOR) |
| | | .appendUtf8("dc=example").toByteString()); |
| | | assertEquals(dn.toNormalizedUrlSafeString(), "dc=com,dc=example"); |
| | | } |
| | | |