diff --git a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java index b9709e380880c1caa53fdf3eaf08583efb262a67..94be970e57f19da963ca2225af90f99fefb78b0e 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -23,7 +23,7 @@ import java.util.Arrays; /** * {@link Resource} implementation for a given byte array. - * Creates a ByteArrayInputStreams for the given byte array. + *

Creates a {@link ByteArrayInputStream} for the given byte array. * *

Useful for loading content from any given byte array, * without having to resort to a single-use {@link InputStreamResource}. @@ -31,6 +31,7 @@ import java.util.Arrays; * where JavaMail needs to be able to read the stream multiple times. * * @author Juergen Hoeller + * @author Sam Brannen * @since 1.2.3 * @see java.io.ByteArrayInputStream * @see InputStreamResource @@ -99,11 +100,12 @@ public class ByteArrayResource extends AbstractResource { } /** - * This implementation returns the passed-in description, if any. + * This implementation returns a description that includes the passed-in + * {@code description}, if any. */ @Override public String getDescription() { - return this.description; + return "Byte array resource [" + this.description + "]"; } diff --git a/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java b/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java index 3a37cac97a484a6c61fc2764f5bd107589562a55..b2587f99df4c6bad5309f2dcee83cd8b5074f638 100644 --- a/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -20,17 +20,19 @@ import java.io.IOException; import java.io.InputStream; /** - * {@link Resource} implementation for a given InputStream. Should only - * be used if no specific Resource implementation is applicable. - * In particular, prefer {@link ByteArrayResource} or any of the - * file-based Resource implementations where possible. + * {@link Resource} implementation for a given {@link InputStream}. + *

Should only be used if no other specific {@code Resource} implementation + * is applicable. In particular, prefer {@link ByteArrayResource} or any of the + * file-based {@code Resource} implementations where possible. * - *

In contrast to other Resource implementations, this is a descriptor - * for an already opened resource - therefore returning "true" from - * {@code isOpen()}. Do not use it if you need to keep the resource - * descriptor somewhere, or if you need to read a stream multiple times. + *

In contrast to other {@code Resource} implementations, this is a descriptor + * for an already opened resource - therefore returning {@code true} from + * {@link #isOpen()}. Do not use an {@code InputStreamResource} if you need to + * keep the resource descriptor somewhere, or if you need to read from a stream + * multiple times. * * @author Juergen Hoeller + * @author Sam Brannen * @since 28.12.2003 * @see ByteArrayResource * @see ClassPathResource @@ -99,11 +101,12 @@ public class InputStreamResource extends AbstractResource { } /** - * This implementation returns the passed-in description, if any. + * This implementation returns a description that includes the passed-in + * description, if any. */ @Override public String getDescription() { - return this.description; + return "InputStream resource [" + this.description + "]"; } diff --git a/spring-core/src/main/java/org/springframework/core/io/PathResource.java b/spring-core/src/main/java/org/springframework/core/io/PathResource.java index 8dfd0447eddb0a6a78491891cc6384a888b2667c..641d87635f8e06534fa503f3248ae50ef6590885 100644 --- a/spring-core/src/main/java/org/springframework/core/io/PathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/PathResource.java @@ -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. @@ -33,8 +33,8 @@ import org.springframework.util.Assert; /** * {@link Resource} implementation for {@code java.nio.file.Path} handles. - * Supports resolution as File, and also as URL. - * Implements the extended {@link WritableResource} interface. + *

Supports resolution as File, and also as URL. + *

Implements the extended {@link WritableResource} interface. * * @author Philippe Marschall * @since 4.0 diff --git a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java index 77f8b8bf3e065455957319f1dcf272b48baa6bcc..41aa4a03b480e768dbb80fb844c790800c3d43b5 100644 --- a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java @@ -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. @@ -32,8 +32,8 @@ import org.springframework.util.StringUtils; /** * {@link Resource} implementation for {@code java.net.URL} locators. - * Obviously supports resolution as URL, and also as File in case of - * the "file:" protocol. + *

Supports resolution as a {@code URL} and also as a {@code File} in + * case of the {@code "file:"} protocol. * * @author Juergen Hoeller * @since 28.12.2003 @@ -58,7 +58,7 @@ public class UrlResource extends AbstractFileResolvingResource { /** - * Create a new UrlResource based on the given URI object. + * Create a new {@code UrlResource} based on the given URI object. * @param uri a URI * @throws MalformedURLException if the given URL path is not valid */ @@ -70,7 +70,7 @@ public class UrlResource extends AbstractFileResolvingResource { } /** - * Create a new UrlResource based on the given URL object. + * Create a new {@code UrlResource} based on the given URL object. * @param url a URL */ public UrlResource(URL url) { @@ -81,7 +81,7 @@ public class UrlResource extends AbstractFileResolvingResource { } /** - * Create a new UrlResource based on a URL path. + * Create a new {@code UrlResource} based on a URL path. *

Note: The given path needs to be pre-encoded if necessary. * @param path a URL path * @throws MalformedURLException if the given URL path is not valid @@ -95,7 +95,7 @@ public class UrlResource extends AbstractFileResolvingResource { } /** - * Create a new UrlResource based on a URI specification. + * Create a new {@code UrlResource} based on a URI specification. *

The given parts will automatically get encoded if necessary. * @param protocol the URL protocol to use (e.g. "jar" or "file" - without colon); * also known as "scheme" @@ -109,7 +109,7 @@ public class UrlResource extends AbstractFileResolvingResource { } /** - * Create a new UrlResource based on a URI specification. + * Create a new {@code UrlResource} based on a URI specification. *

The given parts will automatically get encoded if necessary. * @param protocol the URL protocol to use (e.g. "jar" or "file" - without colon); * also known as "scheme" @@ -154,7 +154,7 @@ public class UrlResource extends AbstractFileResolvingResource { /** * This implementation opens an InputStream for the given URL. - * It sets the "UseCaches" flag to {@code false}, + *

It sets the {@code useCaches} flag to {@code false}, * mainly to avoid jar file locking on Windows. * @see java.net.URL#openConnection() * @see java.net.URLConnection#setUseCaches(boolean) @@ -214,7 +214,7 @@ public class UrlResource extends AbstractFileResolvingResource { } /** - * This implementation creates a UrlResource, applying the given path + * This implementation creates a {@code UrlResource}, applying the given path * relative to the path of the underlying URL of this resource descriptor. * @see java.net.URL#URL(java.net.URL, String) */ diff --git a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java index a0ab31fe7d10c22a89db4d7a04c23378f1467185..296e84236553463e61ca4aa21109e9edb04506e4 100644 --- a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java @@ -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. @@ -35,6 +35,7 @@ import org.springframework.util.Assert; * @author Ales Justin * @author Juergen Hoeller * @author Costin Leau + * @author Sam Brannen * @since 3.0 * @see org.jboss.vfs.VirtualFile */ @@ -120,7 +121,7 @@ public class VfsResource extends AbstractResource { @Override public String getDescription() { - return this.resource.toString(); + return "VFS resource [" + this.resource + "]"; } @Override diff --git a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java index 946f33ffbb83ae63735ea20a470b7d35907e2d3b..ad73395acbaf7fa1f02689e8b6c626eb7d2053be 100644 --- a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -32,8 +32,11 @@ import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; /** + * Unit tests for various {@link Resource} implementations. + * * @author Juergen Hoeller * @author Chris Beams + * @author Sam Brannen * @since 09.09.2004 */ public class ResourceTests { @@ -55,7 +58,7 @@ public class ResourceTests { assertFalse(resource.isOpen()); String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); assertEquals("testString", content); - assertEquals("my description", resource.getDescription()); + assertTrue(resource.getDescription().contains("my description")); assertEquals(resource, new ByteArrayResource("testString".getBytes())); } @@ -78,7 +81,7 @@ public class ResourceTests { assertTrue(resource.isOpen()); String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); assertEquals("testString", content); - assertEquals("my description", resource.getDescription()); + assertTrue(resource.getDescription().contains("my description")); assertEquals(resource, new InputStreamResource(is)); } @@ -114,7 +117,6 @@ public class ResourceTests { assertEquals(resource, new ClassPathResource("Resource.class", getClass())); } - @Ignore // passes under eclipse, fails under ant @Test public void testFileSystemResource() throws IOException { Resource resource = new FileSystemResource(getClass().getResource("Resource.class").getFile()); diff --git a/spring-core/src/test/java/org/springframework/core/io/support/ResourcePropertySourceTests.java b/spring-core/src/test/java/org/springframework/core/io/support/ResourcePropertySourceTests.java index 1bbc3cb2a1c383289fb3ed6256f06f088b29e2fc..ff64fbf337f13e2b4fd9e6f59e411392db449429 100644 --- a/spring-core/src/test/java/org/springframework/core/io/support/ResourcePropertySourceTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/support/ResourcePropertySourceTests.java @@ -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. @@ -31,6 +31,7 @@ import static org.junit.Assert.*; * Unit tests for {@link ResourcePropertySource}. * * @author Chris Beams + * @author Sam Brannen * @since 3.1 */ public class ResourcePropertySourceTests { @@ -46,57 +47,57 @@ public class ResourcePropertySourceTests { @Test public void withLocationAndGeneratedName() throws IOException { PropertySource ps = new ResourcePropertySource(PROPERTIES_LOCATION); - assertEquals(ps.getProperty("foo"), "bar"); + assertEquals("bar", ps.getProperty("foo")); assertThat(ps.getName(), is(PROPERTIES_RESOURCE_DESCRIPTION)); } @Test public void xmlWithLocationAndGeneratedName() throws IOException { PropertySource ps = new ResourcePropertySource(XML_PROPERTIES_LOCATION); - assertEquals(ps.getProperty("foo"), "bar"); + assertEquals("bar", ps.getProperty("foo")); assertThat(ps.getName(), is(XML_PROPERTIES_RESOURCE_DESCRIPTION)); } @Test public void withLocationAndExplicitName() throws IOException { PropertySource ps = new ResourcePropertySource("ps1", PROPERTIES_LOCATION); - assertEquals(ps.getProperty("foo"), "bar"); + assertEquals("bar", ps.getProperty("foo")); assertThat(ps.getName(), is("ps1")); } @Test public void withLocationAndExplicitNameAndExplicitClassLoader() throws IOException { PropertySource ps = new ResourcePropertySource("ps1", PROPERTIES_LOCATION, getClass().getClassLoader()); - assertEquals(ps.getProperty("foo"), "bar"); + assertEquals("bar", ps.getProperty("foo")); assertThat(ps.getName(), is("ps1")); } @Test public void withLocationAndGeneratedNameAndExplicitClassLoader() throws IOException { PropertySource ps = new ResourcePropertySource(PROPERTIES_LOCATION, getClass().getClassLoader()); - assertEquals(ps.getProperty("foo"), "bar"); + assertEquals("bar", ps.getProperty("foo")); assertThat(ps.getName(), is(PROPERTIES_RESOURCE_DESCRIPTION)); } @Test public void withResourceAndGeneratedName() throws IOException { PropertySource ps = new ResourcePropertySource(new ClassPathResource(PROPERTIES_PATH)); - assertEquals(ps.getProperty("foo"), "bar"); + assertEquals("bar", ps.getProperty("foo")); assertThat(ps.getName(), is(PROPERTIES_RESOURCE_DESCRIPTION)); } @Test public void withResourceAndExplicitName() throws IOException { PropertySource ps = new ResourcePropertySource("ps1", new ClassPathResource(PROPERTIES_PATH)); - assertEquals(ps.getProperty("foo"), "bar"); + assertEquals("bar", ps.getProperty("foo")); assertThat(ps.getName(), is("ps1")); } @Test - public void withResourceHavingNoDescriptionAndGeneratedName() throws IOException { + public void withResourceHavingNoDescription() throws IOException { PropertySource ps = new ResourcePropertySource(new ByteArrayResource("foo=bar".getBytes(), "")); - assertEquals(ps.getProperty("foo"), "bar"); - assertTrue(ps.getName().startsWith("ByteArrayResource@")); + assertEquals("bar", ps.getProperty("foo")); + assertEquals("Byte array resource []", ps.getName()); } }