From 88cfe5045d77d433ce02b0ef10ee84c9d4fb15e2 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 23 May 2014 15:17:15 +0000
Subject: [PATCH] (CR-3599) Convert all protocols message to use ByteArrayBuilder + ByteArrayScanner
---
opends/src/server/org/opends/server/replication/protocol/ResetGenerationIdMsg.java | 61 +++++++-----------------------
1 files changed, 14 insertions(+), 47 deletions(-)
diff --git a/opends/src/server/org/opends/server/replication/protocol/ResetGenerationIdMsg.java b/opends/src/server/org/opends/server/replication/protocol/ResetGenerationIdMsg.java
index 44b9515..657fcf9 100644
--- a/opends/src/server/org/opends/server/replication/protocol/ResetGenerationIdMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/ResetGenerationIdMsg.java
@@ -22,23 +22,19 @@
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions copyright 2013 ForgeRock AS.
+ * Portions copyright 2013-2014 ForgeRock AS.
*/
package org.opends.server.replication.protocol;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.util.zip.DataFormatException;
-
/**
* This message is used by an LDAP server to communicate to the topology
* that the generation must be reset for the domain.
*/
public class ResetGenerationIdMsg extends ReplicationMsg
{
- private long generationId;
+ private final long generationId;
/**
* Creates a new message.
@@ -57,52 +53,25 @@
* @throws DataFormatException If the byte array does not contain a valid
* encoded form of the WindowMessage.
*/
- public ResetGenerationIdMsg(byte[] in) throws DataFormatException
+ ResetGenerationIdMsg(byte[] in) throws DataFormatException
{
- try
+ final ByteArrayScanner scanner = new ByteArrayScanner(in);
+ if (scanner.nextByte() != MSG_TYPE_RESET_GENERATION_ID)
{
- if (in[0] != MSG_TYPE_RESET_GENERATION_ID)
- throw new
- DataFormatException("input is not a valid GenerationId Message");
-
- int pos = 1;
-
- /* read the generationId */
- int length = getNextLength(in, pos);
- generationId = Long.valueOf(new String(in, pos, length,
- "UTF-8"));
- pos += length +1;
- } catch (UnsupportedEncodingException e)
- {
- throw new DataFormatException("UTF-8 is not supported by this jvm.");
+ throw new DataFormatException(
+ "input is not a valid GenerationId Message");
}
-
+ generationId = scanner.nextLongUTF8();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public byte[] getBytes(short protocolVersion)
{
- try
- {
- ByteArrayOutputStream oStream = new ByteArrayOutputStream();
-
- /* Put the message type */
- oStream.write(MSG_TYPE_RESET_GENERATION_ID);
-
- // Put the generationId
- oStream.write(String.valueOf(generationId).getBytes("UTF-8"));
- oStream.write(0);
-
- return oStream.toByteArray();
- }
- catch (IOException e)
- {
- // never happens
- return null;
- }
+ final ByteArrayBuilder builder = new ByteArrayBuilder();
+ builder.append(MSG_TYPE_RESET_GENERATION_ID);
+ builder.appendUTF8(generationId);
+ return builder.toByteArray();
}
/**
@@ -115,9 +84,7 @@
return this.generationId;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public String toString()
{
--
Gitblit v1.10.0