Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Refactor the original code
  • Loading branch information
komamitsu committed Jan 21, 2023
commit ac9d28aa43438f303752d54bb0bdb87a29b48e20
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* MessageBufferInput adapter for byte arrays
*/
public class ArrayBufferInput
implements MessageBufferInput<byte[]>
implements MessageBufferInput
{
private MessageBuffer buffer;
private boolean isEmpty;
Expand Down Expand Up @@ -66,14 +66,9 @@ public MessageBuffer reset(MessageBuffer buf)
return old;
}

@Override
public byte[] reset(byte[] arr)
public void reset(byte[] arr)
{
final MessageBuffer messageBuffer = reset(MessageBuffer.wrap(checkNotNull(arr, "input array is null")));
if (messageBuffer == null) {
return null;
}
return messageBuffer.array();
reset(MessageBuffer.wrap(checkNotNull(arr, "input array is null")));
}

public void reset(byte[] arr, int offset, int len)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* {@link MessageBufferInput} adapter for {@link java.nio.ByteBuffer}
*/
public class ByteBufferInput
implements MessageBufferInput<ByteBuffer>
implements MessageBufferInput
{
private ByteBuffer input;
private boolean isRead = false;
Expand All @@ -39,7 +39,6 @@ public ByteBufferInput(ByteBuffer input)
* @param input new buffer
* @return the old buffer
*/
@Override
public ByteBuffer reset(ByteBuffer input)
{
ByteBuffer old = this.input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* {@link MessageBufferInput} adapter for {@link java.nio.channels.ReadableByteChannel}
*/
public class ChannelBufferInput
implements MessageBufferInput<ReadableByteChannel>
implements MessageBufferInput
{
private ReadableByteChannel channel;
private final MessageBuffer buffer;
Expand All @@ -49,8 +49,8 @@ public ChannelBufferInput(ReadableByteChannel channel, int bufferSize)
* @param channel new channel
* @return the old resource
*/
@Override
public ReadableByteChannel reset(ReadableByteChannel channel)
throws IOException
{
ReadableByteChannel old = this.channel;
this.channel = channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* {@link MessageBufferInput} adapter for {@link InputStream}
*/
public class InputStreamBufferInput
implements MessageBufferInput<InputStream>
implements MessageBufferInput
{
private InputStream in;
private final byte[] buffer;
Expand Down Expand Up @@ -60,8 +60,8 @@ public InputStreamBufferInput(InputStream in, int bufferSize)
* @param in new stream
* @return the old resource
*/
@Override
public InputStream reset(InputStream in)
throws IOException
{
InputStream old = this.in;
this.in = in;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* A MessageBufferInput implementation has control of lifecycle of the memory so that it can reuse previously
* allocated memory, use memory pools, or use memory-mapped files.
*/
public interface MessageBufferInput<T>
public interface MessageBufferInput
extends Closeable
{
/**
Expand All @@ -40,8 +40,6 @@ public interface MessageBufferInput<T>
MessageBuffer next()
throws IOException;

T reset(T input);

/**
* Closes the input.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* {@link MessageBufferInput} adapter for {@link MessageBufferInput} Enumeration
*/
public class SequenceMessageBufferInput
implements MessageBufferInput<Void>
implements MessageBufferInput
{
private Enumeration<? extends MessageBufferInput> sequence;
private MessageBufferInput input;
Expand Down Expand Up @@ -54,11 +54,6 @@ public MessageBuffer next() throws IOException
return buffer;
}

@Override
public Void reset(Void input) {
throw new UnsupportedOperationException("reset");
}

private void nextInput() throws IOException
{
if (input != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import scala.jdk.CollectionConverters._
import scala.util.Random

object MessageUnpackerTest {
class SplitMessageBufferInput(array: Array[Array[Byte]]) extends MessageBufferInput[Void] {
class SplitMessageBufferInput(array: Array[Array[Byte]]) extends MessageBufferInput {
var cursor = 0
override def next(): MessageBuffer = {
if (cursor < array.length) {
Expand All @@ -41,9 +41,6 @@ object MessageUnpackerTest {
}
}


override def reset(input: Void): Void = throw new UnsupportedOperationException("reset")

override def close(): Unit = {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ByteStringTest extends AirSpec {
private val byteString = ByteString(createMessagePackData(_.packString(unpackedString)))

private def unpackString(messageBuffer: MessageBuffer) = {
val input = new MessageBufferInput[Void] {
val input = new MessageBufferInput {

private var isRead = false

Expand All @@ -38,8 +38,6 @@ class ByteStringTest extends AirSpec {
messageBuffer
}
override def close(): Unit = {}

override def reset(input: Void): Void = throw new UnsupportedOperationException("reset")
}

MessagePack.newDefaultUnpacker(input).unpackString()
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading