Skip to content

Commit

Permalink
Remove the parts which ByteBuf's 'hasArray()' method is used (closes b…
Browse files Browse the repository at this point in the history
  • Loading branch information
aldemirenes committed Aug 28, 2017
1 parent d0e6612 commit 2d543ec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
23 changes: 18 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
Expand Down Expand Up @@ -130,19 +143,19 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
<version>2.6.2</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
<version>2.6.2</version>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.39.Final</version>
<version>4.1.10.Final</version>
</dependency>

<dependency>
Expand All @@ -154,7 +167,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.4</version>
<version>2.8.8</version>
</dependency>

<dependency>
Expand All @@ -173,7 +186,7 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative</artifactId>
<version>1.1.33.Fork18</version>
<version>2.0.6.Final</version>
<classifier>${os.detected.classifier}</classifier>
<scope>test</scope>
</dependency>
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/com/github/brainlag/nsq/frames/MessageFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ public void setData(byte[] bytes) {
timestamp = buf.readLong();
attempts = buf.readShort();
buf.readBytes(messageId);
ByteBuf messageBodyBuf = buf.readBytes(buf.readableBytes());
if (messageBodyBuf.hasArray()) {
messageBody = messageBodyBuf.array();
} else {
byte[] array = new byte[messageBodyBuf.readableBytes()];
messageBodyBuf.readBytes(array);
messageBody = array;
}
buf.release();
messageBodyBuf.release();

byte[] array = new byte[buf.readableBytes()];
buf.readBytes(array);
messageBody = array;
}

public long getTimestamp() {
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/github/brainlag/nsq/netty/NSQDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
}
frame.setSize(size);
ByteBuf bytes = in.readBytes(frame.getSize() - 4); //subtract 4 because the frame id is included
if (bytes.hasArray()) {
frame.setData(bytes.array());
} else {
byte[] array = new byte[bytes.readableBytes()];
bytes.readBytes(array);
frame.setData(array);
}
byte[] array = new byte[bytes.readableBytes()];
bytes.readBytes(array);
frame.setData(array);

out.add(frame);
bytes.release();
}
Expand Down

0 comments on commit 2d543ec

Please sign in to comment.