Minor revision of reactive support layout (ahead of 5.0 M1)

DataSourceUtils moved to main core.io.buffer package.
Consistently named Jackson2JsonDecoder/Encoder and Jaxb2XmlDecoder/Encoder.
Plenty of related polishing.
This commit is contained in:
Juergen Hoeller
2016-07-26 15:39:32 +02:00
parent 3d6a5bcd66
commit c13f8419f9
51 changed files with 335 additions and 378 deletions

View File

@@ -16,8 +16,6 @@
package org.springframework.core.codec;
import java.nio.charset.StandardCharsets;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,7 +26,6 @@ import reactor.test.TestSubscriber;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.support.DataBufferUtils;
import org.springframework.util.MimeTypeUtils;
import static org.junit.Assert.assertFalse;

View File

@@ -26,9 +26,8 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
import org.springframework.core.io.buffer.support.DataBufferUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.core.io.buffer.support;
package org.springframework.core.io.buffer;
import java.io.InputStream;
import java.net.URI;
@@ -26,10 +26,7 @@ import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.test.TestSubscriber;
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
import org.springframework.core.io.buffer.DataBuffer;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
@@ -38,10 +35,8 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void readChannel() throws Exception {
URI uri = DataBufferUtilsTests.class.getResource("DataBufferUtilsTests.txt")
.toURI();
URI uri = DataBufferUtilsTests.class.getResource("DataBufferUtilsTests.txt").toURI();
FileChannel channel = FileChannel.open(Paths.get(uri), StandardOpenOption.READ);
Flux<DataBuffer> flux = DataBufferUtils.read(channel, this.bufferFactory, 3);
TestSubscriber
@@ -57,10 +52,8 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void readUnalignedChannel() throws Exception {
URI uri = DataBufferUtilsTests.class.getResource("DataBufferUtilsTests.txt")
.toURI();
URI uri = DataBufferUtilsTests.class.getResource("DataBufferUtilsTests.txt").toURI();
FileChannel channel = FileChannel.open(Paths.get(uri), StandardOpenOption.READ);
Flux<DataBuffer> flux = DataBufferUtils.read(channel, this.bufferFactory, 5);
TestSubscriber
@@ -77,9 +70,7 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void readInputStream() {
InputStream is = DataBufferUtilsTests.class
.getResourceAsStream("DataBufferUtilsTests.txt");
InputStream is = DataBufferUtilsTests.class.getResourceAsStream("DataBufferUtilsTests.txt");
Flux<DataBuffer> flux = DataBufferUtils.read(is, this.bufferFactory, 3);
TestSubscriber
@@ -97,7 +88,6 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {
DataBuffer bar = stringBuffer("bar");
DataBuffer baz = stringBuffer("baz");
Flux<DataBuffer> flux = Flux.just(foo, bar, baz);
Flux<DataBuffer> result = DataBufferUtils.takeUntilByteCount(flux, 5L);
TestSubscriber
@@ -109,4 +99,4 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {
release(baz);
}
}
}

View File

@@ -24,16 +24,15 @@ import org.springframework.util.Assert;
/**
* Utility class for working with {@link DataBuffer}s in tests.
*
* <p>Note that this class is in the {@code test} tree of the project: the methods
* contained herein are not suitable for production code bases.
* <p>Note that this class is in the {@code test} tree of the project:
* the methods contained herein are not suitable for production code bases.
*
* @author Arjen Poutsma
*/
public abstract class DataBufferTestUtils {
/**
* Dumps all the bytes in the given data buffer, and returns them as a byte array.
*
* Dump all the bytes in the given data buffer, and returns them as a byte array.
* <p>Note that this method reads the entire buffer into the heap, which might
* consume a lot of memory.
* @param buffer the data buffer to dump the bytes of
@@ -41,15 +40,13 @@ public abstract class DataBufferTestUtils {
*/
public static byte[] dumpBytes(DataBuffer buffer) {
Assert.notNull(buffer, "'buffer' must not be null");
byte[] bytes = new byte[buffer.readableByteCount()];
buffer.read(bytes);
return bytes;
}
/**
* Dumps all the bytes in the given data buffer, and returns them as a string.
*
* Dump all the bytes in the given data buffer, and returns them as a string.
* <p>Note that this method reads the entire buffer into the heap, which might
* consume a lot of memory.
* @param buffer the data buffer to dump the string contents of
@@ -58,8 +55,8 @@ public abstract class DataBufferTestUtils {
*/
public static String dumpString(DataBuffer buffer, Charset charset) {
Assert.notNull(charset, "'charset' must not be null");
byte[] bytes = dumpBytes(buffer);
return new String(bytes, charset);
}
}