moved getInputStream() not-null requirement to InputStreamSource itself
This commit is contained in:
@@ -25,7 +25,6 @@ import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.springframework.core.NestedIOException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
/**
|
||||
@@ -113,16 +112,14 @@ public abstract class AbstractResource implements Resource {
|
||||
* content length. Subclasses will almost always be able to provide
|
||||
* a more optimal version of this, e.g. checking a File length.
|
||||
* @see #getInputStream()
|
||||
* @throws IllegalStateException if {@link #getInputStream()} returns null.
|
||||
*/
|
||||
public long contentLength() throws IOException {
|
||||
InputStream is = this.getInputStream();
|
||||
Assert.state(is != null, "resource input stream must not be null");
|
||||
InputStream is = getInputStream();
|
||||
try {
|
||||
long size = 0;
|
||||
byte[] buf = new byte[255];
|
||||
int read;
|
||||
while((read = is.read(buf)) != -1) {
|
||||
while ((read = is.read(buf)) != -1) {
|
||||
size += read;
|
||||
}
|
||||
return size;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -47,6 +47,7 @@ public interface InputStreamSource {
|
||||
* as JavaMail, which needs to be able to read the stream multiple times when
|
||||
* creating mail attachments. For such a use case, it is <i>required</i>
|
||||
* that each <code>getInputStream()</code> call returns a fresh stream.
|
||||
* @return the input stream for the underlying resource (must not be {@code null})
|
||||
* @throws IOException if the stream could not be opened
|
||||
* @see org.springframework.mail.javamail.MimeMessageHelper#addAttachment(String, InputStreamSource)
|
||||
*/
|
||||
|
||||
@@ -133,9 +133,4 @@ public interface Resource extends InputStreamSource {
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @return the input stream for the underlying resource (must not be {@code null}).
|
||||
*/
|
||||
public InputStream getInputStream() throws IOException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user