Browse Source

Move spring-web-reactive classes to spring-core

pull/1111/head
Rossen Stoyanchev 10 years ago
parent
commit
2e8326220b
  1. 4
      build.gradle
  2. 0
      spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java
  3. 0
      spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java
  4. 0
      spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java
  5. 0
      spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java
  6. 0
      spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java
  7. 0
      spring-core/src/main/java/org/springframework/core/codec/CodecException.java
  8. 0
      spring-core/src/main/java/org/springframework/core/codec/Decoder.java
  9. 0
      spring-core/src/main/java/org/springframework/core/codec/Encoder.java
  10. 0
      spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java
  11. 0
      spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java
  12. 0
      spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java
  13. 0
      spring-core/src/main/java/org/springframework/core/codec/StringEncoder.java
  14. 0
      spring-core/src/main/java/org/springframework/core/codec/package-info.java
  15. 0
      spring-core/src/main/java/org/springframework/core/convert/support/MonoToCompletableFutureConverter.java
  16. 0
      spring-core/src/main/java/org/springframework/core/convert/support/ReactorToRxJava1Converter.java
  17. 0
      spring-core/src/main/java/org/springframework/core/io/buffer/DataBuffer.java
  18. 0
      spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferFactory.java
  19. 0
      spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java
  20. 0
      spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferFactory.java
  21. 0
      spring-core/src/main/java/org/springframework/core/io/buffer/FlushingDataBuffer.java
  22. 0
      spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java
  23. 0
      spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBufferFactory.java
  24. 0
      spring-core/src/main/java/org/springframework/core/io/buffer/PooledDataBuffer.java
  25. 0
      spring-core/src/main/java/org/springframework/core/io/buffer/support/DataBufferUtils.java
  26. 53
      spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java
  27. 32
      spring-core/src/main/java/org/springframework/util/ResourceUtils.java
  28. 0
      spring-core/src/main/java/org/springframework/util/xml/AbstractXMLEventReader.java
  29. 0
      spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java
  30. 12
      spring-core/src/main/java/org/springframework/util/xml/StaxUtils.java
  31. 11
      spring-core/src/test/java/org/springframework/core/codec/ByteBufferDecoderTests.java
  32. 15
      spring-core/src/test/java/org/springframework/core/codec/ByteBufferEncoderTests.java
  33. 25
      spring-core/src/test/java/org/springframework/core/codec/ResourceDecoderTests.java
  34. 21
      spring-core/src/test/java/org/springframework/core/codec/ResourceEncoderTests.java
  35. 12
      spring-core/src/test/java/org/springframework/core/codec/StringDecoderTests.java
  36. 11
      spring-core/src/test/java/org/springframework/core/codec/StringEncoderTests.java
  37. 0
      spring-core/src/test/java/org/springframework/core/convert/support/MonoToCompletableFutureConverterTests.java
  38. 0
      spring-core/src/test/java/org/springframework/core/convert/support/ReactorToRxJava1ConverterTests.java
  39. 0
      spring-core/src/test/java/org/springframework/core/io/buffer/AbstractDataBufferAllocatingTestCase.java
  40. 0
      spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java
  41. 0
      spring-core/src/test/java/org/springframework/core/io/buffer/PooledDataBufferTests.java
  42. 0
      spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtils.java
  43. 0
      spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java
  44. 0
      spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferUtilsTests.java
  45. 0
      spring-core/src/test/java/org/springframework/util/xml/ListBasedXMLEventReaderTests.java
  46. 0
      spring-core/src/test/resources/org/springframework/core/io/buffer/support/DataBufferUtilsTests.txt
  47. 4
      spring-web-reactive/src/main/java/org/springframework/core/convert/support/package-info.java
  48. 59
      spring-web-reactive/src/main/java/org/springframework/core/io/support/ResourceUtils2.java
  49. 4
      spring-web-reactive/src/main/java/org/springframework/http/converter/reactive/ResourceHttpMessageConverter.java
  50. 87
      spring-web-reactive/src/main/java/org/springframework/util/MimeTypeUtils2.java
  51. 38
      spring-web-reactive/src/main/java/org/springframework/util/xml/StaxUtils2.java

4
build.gradle

@ -363,6 +363,10 @@ project("spring-core") { @@ -363,6 +363,10 @@ project("spring-core") {
compile("commons-logging:commons-logging:1.2")
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
optional("net.sf.jopt-simple:jopt-simple:5.0.2")
optional("org.reactivestreams:reactive-streams:1.0.0")
optional("io.projectreactor:reactor-core:${reactorCoreVersion}")
optional "io.reactivex:rxjava:${rxJavaVersion}"
optional("io.netty:netty-buffer:${nettyVersion}")
testCompile("org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}")
testCompile("xmlunit:xmlunit:${xmlunitVersion}")
testCompile("com.fasterxml.woodstox:woodstox-core:5.0.2") {

0
spring-web-reactive/src/main/java/org/springframework/core/codec/AbstractDecoder.java → spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/AbstractEncoder.java → spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java → spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java → spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java → spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/CodecException.java → spring-core/src/main/java/org/springframework/core/codec/CodecException.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/Decoder.java → spring-core/src/main/java/org/springframework/core/codec/Decoder.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/Encoder.java → spring-core/src/main/java/org/springframework/core/codec/Encoder.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/ResourceDecoder.java → spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/ResourceEncoder.java → spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/StringDecoder.java → spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/StringEncoder.java → spring-core/src/main/java/org/springframework/core/codec/StringEncoder.java

0
spring-web-reactive/src/main/java/org/springframework/core/codec/package-info.java → spring-core/src/main/java/org/springframework/core/codec/package-info.java

0
spring-web-reactive/src/main/java/org/springframework/core/convert/support/MonoToCompletableFutureConverter.java → spring-core/src/main/java/org/springframework/core/convert/support/MonoToCompletableFutureConverter.java

0
spring-web-reactive/src/main/java/org/springframework/core/convert/support/ReactorToRxJava1Converter.java → spring-core/src/main/java/org/springframework/core/convert/support/ReactorToRxJava1Converter.java

0
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBuffer.java → spring-core/src/main/java/org/springframework/core/io/buffer/DataBuffer.java

0
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DataBufferFactory.java → spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferFactory.java

0
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java → spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java

0
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferFactory.java → spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferFactory.java

0
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/FlushingDataBuffer.java → spring-core/src/main/java/org/springframework/core/io/buffer/FlushingDataBuffer.java

0
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java → spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java

0
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/NettyDataBufferFactory.java → spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBufferFactory.java

0
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/PooledDataBuffer.java → spring-core/src/main/java/org/springframework/core/io/buffer/PooledDataBuffer.java

0
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/support/DataBufferUtils.java → spring-core/src/main/java/org/springframework/core/io/buffer/support/DataBufferUtils.java

53
spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
package org.springframework.util;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
@ -26,8 +28,13 @@ import java.util.Iterator; @@ -26,8 +28,13 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import javax.activation.FileTypeMap;
import javax.activation.MimetypesFileTypeMap;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.MimeType.SpecificityComparator;
/**
@ -49,6 +56,11 @@ public abstract class MimeTypeUtils { @@ -49,6 +56,11 @@ public abstract class MimeTypeUtils {
private static Charset US_ASCII = Charset.forName("US-ASCII");
private static final FileTypeMap fileTypeMap;
static {
fileTypeMap = initFileTypeMap();
}
/**
* Public constant mime type that includes all media ranges (i.e. "*/*").
@ -208,6 +220,31 @@ public abstract class MimeTypeUtils { @@ -208,6 +220,31 @@ public abstract class MimeTypeUtils {
TEXT_XML = MimeType.valueOf(TEXT_XML_VALUE);
}
private static FileTypeMap initFileTypeMap() {
// See if we can find the extended mime.types from the context-support module...
Resource mappingLocation = new ClassPathResource("org/springframework/mail/javamail/mime.types");
if (mappingLocation.exists()) {
InputStream inputStream = null;
try {
inputStream = mappingLocation.getInputStream();
return new MimetypesFileTypeMap(inputStream);
}
catch (IOException ex) {
// ignore
}
finally {
if (inputStream != null) {
try {
inputStream.close();
}
catch (IOException ex) {
// ignore
}
}
}
}
return FileTypeMap.getDefaultFileTypeMap();
}
/**
* Parse the given String into a single {@code MimeType}.
@ -285,6 +322,22 @@ public abstract class MimeTypeUtils { @@ -285,6 +322,22 @@ public abstract class MimeTypeUtils {
return result;
}
/**
* Returns the {@code MimeType} of the given file name, using the Java Activation
* Framework.
* @param filename the filename whose mime type is to be found
* @return the mime type, if any
*/
public static Optional<MimeType> getMimeType(String filename) {
if (filename != null) {
String mimeType = fileTypeMap.getContentType(filename);
if (StringUtils.hasText(mimeType)) {
return Optional.of(parseMimeType(mimeType));
}
}
return Optional.empty();
}
/**
* Return a string representation of the given list of {@code MimeType} objects.
* @param mimeTypes the string to parse

32
spring-core/src/main/java/org/springframework/util/ResourceUtils.java

@ -18,12 +18,18 @@ package org.springframework.util; @@ -18,12 +18,18 @@ package org.springframework.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.DescriptiveResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
/**
* Utility methods for resolving resource locations to files in the
* file system. Mainly for internal use within the framework.
@ -296,6 +302,32 @@ public abstract class ResourceUtils { @@ -296,6 +302,32 @@ public abstract class ResourceUtils {
url.getPath().toLowerCase().endsWith(JAR_FILE_EXTENSION));
}
/**
* Indicates whether the given resource has a file, so that {@link
* Resource#getFile()}
* can be called without an {@link java.io.IOException}.
* @param resource the resource to check
* @return {@code true} if the given resource has a file; {@code false} otherwise
* @since 5.0
*/
public static boolean hasFile(Resource resource) {
Assert.notNull(resource, "'resource' must not be null");
// the following Resource implementations do not support getURI/getFile
if (resource instanceof ByteArrayResource ||
resource instanceof DescriptiveResource ||
resource instanceof InputStreamResource) {
return false;
}
try {
URI resourceUri = resource.getURI();
return URL_PROTOCOL_FILE.equals(resourceUri.getScheme());
}
catch (IOException ignored) {
}
return false;
}
/**
* Extract the URL for the actual jar file from the given URL
* (which may point to a resource in a jar file or to a jar file itself).

0
spring-web-reactive/src/main/java/org/springframework/util/xml/AbstractXMLEventReader.java → spring-core/src/main/java/org/springframework/util/xml/AbstractXMLEventReader.java

0
spring-web-reactive/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java → spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java

12
spring-core/src/main/java/org/springframework/util/xml/StaxUtils.java

@ -16,12 +16,14 @@ @@ -16,12 +16,14 @@
package org.springframework.util.xml;
import java.util.List;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.events.XMLEvent;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.stax.StAXResult;
@ -211,6 +213,16 @@ public abstract class StaxUtils { @@ -211,6 +213,16 @@ public abstract class StaxUtils {
}
}
/**
* Create a {@link XMLEventReader} from the given list of {@link XMLEvent}.
* @param events the list of {@link XMLEvent}s.
* @return an {@code XMLEventReader} that reads from the given events
* @since 5.0
*/
public static XMLEventReader createXMLEventReader(List<XMLEvent> events) {
return new ListBasedXMLEventReader(events);
}
/**
* Create a SAX {@link ContentHandler} that writes to the given StAX {@link XMLStreamWriter}.
* @param streamWriter the StAX stream writer

11
spring-web-reactive/src/test/java/org/springframework/core/codec/ByteBufferDecoderTests.java → spring-core/src/test/java/org/springframework/core/codec/ByteBufferDecoderTests.java

@ -26,7 +26,7 @@ import reactor.core.test.TestSubscriber; @@ -26,7 +26,7 @@ import reactor.core.test.TestSubscriber;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.MediaType;
import org.springframework.util.MimeTypeUtils;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -40,12 +40,9 @@ public class ByteBufferDecoderTests extends AbstractDataBufferAllocatingTestCase @@ -40,12 +40,9 @@ public class ByteBufferDecoderTests extends AbstractDataBufferAllocatingTestCase
@Test
public void canDecode() {
assertTrue(this.decoder.canDecode(ResolvableType.forClass(ByteBuffer.class),
MediaType.TEXT_PLAIN));
assertFalse(this.decoder
.canDecode(ResolvableType.forClass(Integer.class), MediaType.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(ByteBuffer.class),
MediaType.APPLICATION_JSON));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(ByteBuffer.class), MimeTypeUtils.TEXT_PLAIN));
assertFalse(this.decoder.canDecode(ResolvableType.forClass(Integer.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(ByteBuffer.class), MimeTypeUtils.APPLICATION_JSON));
}
@Test

15
spring-web-reactive/src/test/java/org/springframework/core/codec/ByteBufferEncoderTests.java → spring-core/src/test/java/org/springframework/core/codec/ByteBufferEncoderTests.java

@ -28,9 +28,11 @@ import reactor.core.test.TestSubscriber; @@ -28,9 +28,11 @@ import reactor.core.test.TestSubscriber;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.MediaType;
import org.springframework.util.MimeTypeUtils;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Sebastien Deleuze
@ -46,12 +48,9 @@ public class ByteBufferEncoderTests extends AbstractDataBufferAllocatingTestCase @@ -46,12 +48,9 @@ public class ByteBufferEncoderTests extends AbstractDataBufferAllocatingTestCase
@Test
public void canEncode() {
assertTrue(this.encoder.canEncode(ResolvableType.forClass(ByteBuffer.class),
MediaType.TEXT_PLAIN));
assertFalse(this.encoder
.canEncode(ResolvableType.forClass(Integer.class), MediaType.TEXT_PLAIN));
assertTrue(this.encoder.canEncode(ResolvableType.forClass(ByteBuffer.class),
MediaType.APPLICATION_JSON));
assertTrue(this.encoder.canEncode(ResolvableType.forClass(ByteBuffer.class), MimeTypeUtils.TEXT_PLAIN));
assertFalse(this.encoder.canEncode(ResolvableType.forClass(Integer.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.encoder.canEncode(ResolvableType.forClass(ByteBuffer.class), MimeTypeUtils.APPLICATION_JSON));
}
@Test

25
spring-web-reactive/src/test/java/org/springframework/core/codec/ResourceDecoderTests.java → spring-core/src/test/java/org/springframework/core/codec/ResourceDecoderTests.java

@ -28,10 +28,12 @@ import org.springframework.core.io.InputStreamResource; @@ -28,10 +28,12 @@ import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.MediaType;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.StreamUtils;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author Arjen Poutsma
@ -42,17 +44,14 @@ public class ResourceDecoderTests extends AbstractDataBufferAllocatingTestCase { @@ -42,17 +44,14 @@ public class ResourceDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void canDecode() throws Exception {
assertTrue(
this.decoder.canDecode(ResolvableType.forClass(InputStreamResource.class),
MediaType.TEXT_PLAIN));
assertTrue(
this.decoder.canDecode(ResolvableType.forClass(ByteArrayResource.class),
MediaType.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(Resource.class),
MediaType.TEXT_PLAIN));
assertTrue(
this.decoder.canDecode(ResolvableType.forClass(InputStreamResource.class),
MediaType.APPLICATION_JSON));
assertTrue(this.decoder.canDecode(
ResolvableType.forClass(InputStreamResource.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(
ResolvableType.forClass(ByteArrayResource.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(
ResolvableType.forClass(Resource.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(
ResolvableType.forClass(InputStreamResource.class), MimeTypeUtils.APPLICATION_JSON));
}
@Test

21
spring-web-reactive/src/test/java/org/springframework/core/codec/ResourceEncoderTests.java → spring-core/src/test/java/org/springframework/core/codec/ResourceEncoderTests.java

@ -29,7 +29,7 @@ import org.springframework.core.io.InputStreamResource; @@ -29,7 +29,7 @@ import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.MediaType;
import org.springframework.util.MimeTypeUtils;
import static org.junit.Assert.assertTrue;
@ -42,17 +42,14 @@ public class ResourceEncoderTests extends AbstractDataBufferAllocatingTestCase { @@ -42,17 +42,14 @@ public class ResourceEncoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void canEncode() throws Exception {
assertTrue(
this.encoder.canEncode(ResolvableType.forClass(InputStreamResource.class),
MediaType.TEXT_PLAIN));
assertTrue(
this.encoder.canEncode(ResolvableType.forClass(ByteArrayResource.class),
MediaType.TEXT_PLAIN));
assertTrue(this.encoder.canEncode(ResolvableType.forClass(Resource.class),
MediaType.TEXT_PLAIN));
assertTrue(
this.encoder.canEncode(ResolvableType.forClass(InputStreamResource.class),
MediaType.APPLICATION_JSON));
assertTrue(this.encoder.canEncode(
ResolvableType.forClass(InputStreamResource.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.encoder.canEncode(
ResolvableType.forClass(ByteArrayResource.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.encoder.canEncode(
ResolvableType.forClass(Resource.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.encoder.canEncode(
ResolvableType.forClass(InputStreamResource.class), MimeTypeUtils.APPLICATION_JSON));
}
@Test

12
spring-web-reactive/src/test/java/org/springframework/core/codec/StringDecoderTests.java → spring-core/src/test/java/org/springframework/core/codec/StringDecoderTests.java

@ -24,7 +24,7 @@ import reactor.core.test.TestSubscriber; @@ -24,7 +24,7 @@ import reactor.core.test.TestSubscriber;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.MediaType;
import org.springframework.util.MimeTypeUtils;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -41,11 +41,11 @@ public class StringDecoderTests extends AbstractDataBufferAllocatingTestCase { @@ -41,11 +41,11 @@ public class StringDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void canDecode() {
assertTrue(this.decoder.canDecode(ResolvableType.forClass(String.class), MediaType.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(String.class), MediaType.TEXT_HTML));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(String.class), MediaType.APPLICATION_JSON));
assertFalse(this.decoder.canDecode(ResolvableType.forClass(Integer.class), MediaType.TEXT_PLAIN));
assertFalse(this.decoder.canDecode(ResolvableType.forClass(Object.class), MediaType.APPLICATION_JSON));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_HTML));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(String.class), MimeTypeUtils.APPLICATION_JSON));
assertFalse(this.decoder.canDecode(ResolvableType.forClass(Integer.class), MimeTypeUtils.TEXT_PLAIN));
assertFalse(this.decoder.canDecode(ResolvableType.forClass(Object.class), MimeTypeUtils.APPLICATION_JSON));
}
@Test

11
spring-web-reactive/src/test/java/org/springframework/core/codec/StringEncoderTests.java → spring-core/src/test/java/org/springframework/core/codec/StringEncoderTests.java

@ -28,7 +28,7 @@ import reactor.core.test.TestSubscriber; @@ -28,7 +28,7 @@ import reactor.core.test.TestSubscriber;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
import org.springframework.core.io.buffer.support.DataBufferUtils;
import org.springframework.http.MediaType;
import org.springframework.util.MimeTypeUtils;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -48,12 +48,9 @@ public class StringEncoderTests extends AbstractDataBufferAllocatingTestCase { @@ -48,12 +48,9 @@ public class StringEncoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void canWrite() {
assertTrue(this.encoder
.canEncode(ResolvableType.forClass(String.class), MediaType.TEXT_PLAIN));
assertFalse(this.encoder
.canEncode(ResolvableType.forClass(Integer.class), MediaType.TEXT_PLAIN));
assertFalse(this.encoder.canEncode(ResolvableType.forClass(String.class),
MediaType.APPLICATION_JSON));
assertTrue(this.encoder.canEncode(ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN));
assertFalse(this.encoder.canEncode(ResolvableType.forClass(Integer.class), MimeTypeUtils.TEXT_PLAIN));
assertFalse(this.encoder.canEncode(ResolvableType.forClass(String.class), MimeTypeUtils.APPLICATION_JSON));
}
@Test

0
spring-web-reactive/src/test/java/org/springframework/core/convert/support/MonoToCompletableFutureConverterTests.java → spring-core/src/test/java/org/springframework/core/convert/support/MonoToCompletableFutureConverterTests.java

0
spring-web-reactive/src/test/java/org/springframework/core/convert/support/ReactorToRxJava1ConverterTests.java → spring-core/src/test/java/org/springframework/core/convert/support/ReactorToRxJava1ConverterTests.java

0
spring-web-reactive/src/test/java/org/springframework/core/io/buffer/AbstractDataBufferAllocatingTestCase.java → spring-core/src/test/java/org/springframework/core/io/buffer/AbstractDataBufferAllocatingTestCase.java

0
spring-web-reactive/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java → spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java

0
spring-web-reactive/src/test/java/org/springframework/core/io/buffer/PooledDataBufferTests.java → spring-core/src/test/java/org/springframework/core/io/buffer/PooledDataBufferTests.java

0
spring-web-reactive/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtils.java → spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtils.java

0
spring-web-reactive/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java → spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferTestUtilsTests.java

0
spring-web-reactive/src/test/java/org/springframework/core/io/buffer/support/DataBufferUtilsTests.java → spring-core/src/test/java/org/springframework/core/io/buffer/support/DataBufferUtilsTests.java

0
spring-web-reactive/src/test/java/org/springframework/util/xml/ListBasedXMLEventReaderTests.java → spring-core/src/test/java/org/springframework/util/xml/ListBasedXMLEventReaderTests.java

0
spring-web-reactive/src/test/resources/org/springframework/core/io/buffer/support/DataBufferUtilsTests.txt → spring-core/src/test/resources/org/springframework/core/io/buffer/support/DataBufferUtilsTests.txt

4
spring-web-reactive/src/main/java/org/springframework/core/convert/support/package-info.java

@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
/**
* Default implementation of the type conversion system.
*/
package org.springframework.core.convert.support;

59
spring-web-reactive/src/main/java/org/springframework/core/io/support/ResourceUtils2.java

@ -1,59 +0,0 @@ @@ -1,59 +0,0 @@
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core.io.support;
import java.io.IOException;
import java.net.URI;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.DescriptiveResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
/**
* @author Arjen Poutsma
*/
public abstract class ResourceUtils2 {
/**
* Indicates whether the given resource has a file, so that {@link
* Resource#getFile()}
* can be called without an {@link java.io.IOException}.
* @param resource the resource to check
* @return {@code true} if the given resource has a file; {@code false} otherwise
*/
// TODO: refactor into Resource.hasFile() method
public static boolean hasFile(Resource resource) {
Assert.notNull(resource, "'resource' must not be null");
// the following Resource implementations do not support getURI/getFile
if (resource instanceof ByteArrayResource ||
resource instanceof DescriptiveResource ||
resource instanceof InputStreamResource) {
return false;
}
try {
URI resourceUri = resource.getURI();
return ResourceUtils.URL_PROTOCOL_FILE.equals(resourceUri.getScheme());
}
catch (IOException ignored) {
}
return false;
}
}

4
spring-web-reactive/src/main/java/org/springframework/http/converter/reactive/ResourceHttpMessageConverter.java

@ -29,13 +29,13 @@ import org.springframework.core.codec.ResourceDecoder; @@ -29,13 +29,13 @@ import org.springframework.core.codec.ResourceDecoder;
import org.springframework.core.codec.ResourceEncoder;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourceUtils2;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ReactiveHttpOutputMessage;
import org.springframework.http.ZeroCopyHttpOutputMessage;
import org.springframework.http.support.MediaTypeUtils;
import org.springframework.util.MimeTypeUtils2;
import org.springframework.util.ResourceUtils;
/**
* Implementation of {@link HttpMessageConverter} that can read and write
@ -116,7 +116,7 @@ public class ResourceHttpMessageConverter extends CodecHttpMessageConverter<Reso @@ -116,7 +116,7 @@ public class ResourceHttpMessageConverter extends CodecHttpMessageConverter<Reso
}
private static Optional<File> getFile(Resource resource) {
if (ResourceUtils2.hasFile(resource)) {
if (ResourceUtils.hasFile(resource)) {
try {
return Optional.of(resource.getFile());
}

87
spring-web-reactive/src/main/java/org/springframework/util/MimeTypeUtils2.java

@ -1,87 +0,0 @@ @@ -1,87 +0,0 @@
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
import javax.activation.FileTypeMap;
import javax.activation.MimetypesFileTypeMap;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
/**
* TODO: merge into {@link MimeTypeUtils}, and use wherever we still have a runtime check
* to see if JAF is available (i.e. jafPresent). Since JAF has been included in the JDK
* since 1.6, we don't
* need that check anymore. (i.e. {@link org.springframework.http.converter.ResourceHttpMessageConverter}
* @author Arjen Poutsma
*/
public abstract class MimeTypeUtils2 extends MimeTypeUtils {
private static final FileTypeMap fileTypeMap;
static {
fileTypeMap = loadFileTypeMapFromContextSupportModule();
}
private static FileTypeMap loadFileTypeMapFromContextSupportModule() {
// See if we can find the extended mime.types from the context-support module...
Resource mappingLocation =
new ClassPathResource("org/springframework/mail/javamail/mime.types");
if (mappingLocation.exists()) {
InputStream inputStream = null;
try {
inputStream = mappingLocation.getInputStream();
return new MimetypesFileTypeMap(inputStream);
}
catch (IOException ex) {
// ignore
}
finally {
if (inputStream != null) {
try {
inputStream.close();
}
catch (IOException ex) {
// ignore
}
}
}
}
return FileTypeMap.getDefaultFileTypeMap();
}
/**
* Returns the {@code MimeType} of the given file name, using the Java Activation
* Framework.
* @param filename the filename whose mime type is to be found
* @return the mime type, if any
*/
public static Optional<MimeType> getMimeType(String filename) {
if (filename != null) {
String mimeType = fileTypeMap.getContentType(filename);
if (StringUtils.hasText(mimeType)) {
return Optional.of(parseMimeType(mimeType));
}
}
return Optional.empty();
}
}

38
spring-web-reactive/src/main/java/org/springframework/util/xml/StaxUtils2.java

@ -1,38 +0,0 @@ @@ -1,38 +0,0 @@
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.util.xml;
import java.util.List;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.events.XMLEvent;
/**
* TODO: to be merged with {@link StaxUtils}.
* @author Arjen Poutsma
*/
public abstract class StaxUtils2 {
/**
* Create a {@link XMLEventReader} from the given list of {@link XMLEvent}.
* @param events the list of {@link XMLEvent}s.
* @return an {@code XMLEventReader} that reads from the given events
*/
public static XMLEventReader createXMLEventReader(List<XMLEvent> events) {
return new ListBasedXMLEventReader(events);
}
}
Loading…
Cancel
Save