Various DataBuffer improvements

- Added fromIndex parameter to indexOf and lastIndexOf
- Moved DataBuffer.tokenize to StringEncoder, as that's the only place
  it's used.
This commit is contained in:
Arjen Poutsma
2016-06-10 12:26:06 +02:00
parent 622d11dbce
commit ea21643a29
8 changed files with 77 additions and 88 deletions

View File

@@ -82,8 +82,7 @@ public class StringDecoderTests extends AbstractDataBufferAllocatingTestCase {
TestSubscriber
.subscribe(output)
.assertNoError()
.assertComplete()
.assertValues("foo", "bar", "baz");
.assertComplete().assertValues("\n", "foo\r", "\n", "bar\r", "\n", "baz");
}
@Test

View File

@@ -190,10 +190,16 @@ public class DataBufferTests extends AbstractDataBufferAllocatingTestCase {
DataBuffer buffer = createDataBuffer(3);
buffer.write(new byte[]{'a', 'b', 'c'});
int result = buffer.indexOf(b -> b == 'c');
int result = buffer.indexOf(b -> b == 'c', 0);
assertEquals(2, result);
result = buffer.indexOf(b -> b == 'z');
result = buffer.indexOf(b -> b == 'c', Integer.MIN_VALUE);
assertEquals(2, result);
result = buffer.indexOf(b -> b == 'c', Integer.MAX_VALUE);
assertEquals(-1, result);
result = buffer.indexOf(b -> b == 'z', 0);
assertEquals(-1, result);
release(buffer);
@@ -204,10 +210,16 @@ public class DataBufferTests extends AbstractDataBufferAllocatingTestCase {
DataBuffer buffer = createDataBuffer(3);
buffer.write(new byte[]{'a', 'b', 'c'});
int result = buffer.lastIndexOf(b -> b == 'b');
int result = buffer.lastIndexOf(b -> b == 'b', 3);
assertEquals(1, result);
result = buffer.lastIndexOf(b -> b == 'z');
result = buffer.lastIndexOf(b -> b == 'b', Integer.MAX_VALUE);
assertEquals(1, result);
result = buffer.lastIndexOf(b -> b == 'b', Integer.MIN_VALUE);
assertEquals(-1, result);
result = buffer.lastIndexOf(b -> b == 'z', 0);
assertEquals(-1, result);
release(buffer);

View File

@@ -19,10 +19,8 @@ package org.springframework.core.io.buffer.support;
import java.io.InputStream;
import java.net.URI;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.List;
import org.junit.Test;
import reactor.core.publisher.Flux;
@@ -31,7 +29,6 @@ import reactor.core.test.TestSubscriber;
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
import org.springframework.core.io.buffer.DataBuffer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/**
@@ -112,23 +109,4 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {
release(baz);
}
@Test
public void tokenize() {
DataBuffer dataBuffer = stringBuffer("-foo--bar-");
List<DataBuffer> results = DataBufferUtils.tokenize(dataBuffer, b -> b == '-');
assertEquals(2, results.size());
DataBuffer result = results.get(0);
String value = DataBufferTestUtils.dumpString(result, StandardCharsets.UTF_8);
assertEquals("foo", value);
result = results.get(1);
value = DataBufferTestUtils.dumpString(result, StandardCharsets.UTF_8);
assertEquals("bar", value);
results.stream().forEach(b -> release(b));
}
}