parent
7e8ffc7bf5
commit
1e26d17a3d
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.core.convert.support;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -26,8 +27,8 @@ import org.springframework.core.convert.TypeDescriptor;
|
|||
import org.springframework.core.convert.converter.ConditionalGenericConverter;
|
||||
|
||||
/**
|
||||
* Converts a {@link ByteBuffer} directly to and from {@code byte[]}s and indirectly to
|
||||
* any type that the {@link ConversionService} support via {@code byte[]}.
|
||||
* Converts a {@link ByteBuffer} directly to and from {@code byte[]}s and indirectly
|
||||
* to any type that the {@link ConversionService} support via {@code byte[]}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 4.0
|
||||
|
|
@ -47,7 +48,7 @@ final class ByteBufferConverter implements ConditionalGenericConverter {
|
|||
}
|
||||
|
||||
|
||||
private ConversionService conversionService;
|
||||
private final ConversionService conversionService;
|
||||
|
||||
|
||||
public ByteBufferConverter(ConversionService conversionService) {
|
||||
|
|
@ -72,18 +73,17 @@ final class ByteBufferConverter implements ConditionalGenericConverter {
|
|||
}
|
||||
|
||||
private boolean matchesFromByteBuffer(TypeDescriptor targetType) {
|
||||
return (targetType.isAssignableTo(BYTE_ARRAY_TYPE) || this.conversionService.canConvert(
|
||||
BYTE_ARRAY_TYPE, targetType));
|
||||
return (targetType.isAssignableTo(BYTE_ARRAY_TYPE) ||
|
||||
this.conversionService.canConvert(BYTE_ARRAY_TYPE, targetType));
|
||||
}
|
||||
|
||||
private boolean matchesToByteBuffer(TypeDescriptor sourceType) {
|
||||
return (sourceType.isAssignableTo(BYTE_ARRAY_TYPE) || this.conversionService.canConvert(
|
||||
sourceType, BYTE_ARRAY_TYPE));
|
||||
return (sourceType.isAssignableTo(BYTE_ARRAY_TYPE) ||
|
||||
this.conversionService.canConvert(sourceType, BYTE_ARRAY_TYPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convert(Object source, TypeDescriptor sourceType,
|
||||
TypeDescriptor targetType) {
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
if (sourceType.isAssignableTo(BYTE_BUFFER_TYPE)) {
|
||||
return convertFromByteBuffer((ByteBuffer) source, targetType);
|
||||
}
|
||||
|
|
@ -104,11 +104,17 @@ final class ByteBufferConverter implements ConditionalGenericConverter {
|
|||
}
|
||||
|
||||
private Object convertToByteBuffer(Object source, TypeDescriptor sourceType) {
|
||||
byte[] bytes = (byte[]) (source instanceof byte[] ? source
|
||||
: this.conversionService.convert(source, sourceType, BYTE_ARRAY_TYPE));
|
||||
byte[] bytes = (byte[]) (source instanceof byte[] ? source :
|
||||
this.conversionService.convert(source, sourceType, BYTE_ARRAY_TYPE));
|
||||
|
||||
ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
|
||||
byteBuffer.put(bytes);
|
||||
byteBuffer.rewind();
|
||||
|
||||
// Extra cast necessary for compiling on JDK 9 plus running on JDK 8, since
|
||||
// otherwise the overridden ByteBuffer-returning rewind method would be chosen
|
||||
// which isn't available on JDK 8.
|
||||
((Buffer) byteBuffer).rewind();
|
||||
|
||||
return byteBuffer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
|||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.JdkVersion;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
@ -82,7 +83,8 @@ public class PathMatchingResourcePatternResolverTests {
|
|||
public void testSingleResourceInJar() throws IOException {
|
||||
Resource[] resources = resolver.getResources("java/net/URL.class");
|
||||
assertEquals(1, resources.length);
|
||||
assertProtocolAndFilename(resources[0], "jar", "URL.class");
|
||||
String expectedProtocol = (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_19 ? "jar" : "jrt");
|
||||
assertProtocolAndFilename(resources[0], expectedProtocol, "URL.class");
|
||||
}
|
||||
|
||||
@Ignore // passes under eclipse, fails under ant
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
|
|
@ -24,12 +24,6 @@ package org.springframework.tests;
|
|||
*/
|
||||
public enum JavaVersion {
|
||||
|
||||
|
||||
/**
|
||||
* Java 1.5
|
||||
*/
|
||||
JAVA_15("1.5", 15),
|
||||
|
||||
/**
|
||||
* Java 1.6
|
||||
*/
|
||||
|
|
@ -43,7 +37,12 @@ public enum JavaVersion {
|
|||
/**
|
||||
* Java 1.8
|
||||
*/
|
||||
JAVA_18("1.8", 18);
|
||||
JAVA_18("1.8", 18),
|
||||
|
||||
/**
|
||||
* Java 1.9
|
||||
*/
|
||||
JAVA_19("1.9", 19);
|
||||
|
||||
|
||||
private static final JavaVersion runningVersion = findRunningVersion();
|
||||
|
|
@ -55,7 +54,7 @@ public enum JavaVersion {
|
|||
return candidate;
|
||||
}
|
||||
}
|
||||
return JavaVersion.JAVA_15;
|
||||
return JavaVersion.JAVA_16;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -81,16 +80,16 @@ public enum JavaVersion {
|
|||
* @return {@code true} if the specified version is at least this version
|
||||
*/
|
||||
public boolean isAtLeast(JavaVersion version) {
|
||||
return this.value >= version.value;
|
||||
return (this.value >= version.value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current running JDK version. If the current version cannot be
|
||||
* determined {@link #JAVA_15} will be returned.
|
||||
* determined {@link #JAVA_16} will be returned.
|
||||
* @return the JDK version
|
||||
*/
|
||||
public static JavaVersion runningVersion() {
|
||||
return runningVersion;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
|
|
@ -36,8 +36,8 @@ public class JavaVersionTests {
|
|||
|
||||
@Test
|
||||
public void isAtLeast() throws Exception {
|
||||
assertTrue(JavaVersion.JAVA_16.isAtLeast(JavaVersion.JAVA_15));
|
||||
assertTrue(JavaVersion.JAVA_16.isAtLeast(JavaVersion.JAVA_16));
|
||||
assertFalse(JavaVersion.JAVA_16.isAtLeast(JavaVersion.JAVA_17));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue