Skip to content

Commit

Permalink
moved getInputStream() not-null requirement to InputStreamSource itself
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Mar 14, 2012
1 parent 79d9f7a commit d22c8ac
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.net.URL;

import org.springframework.core.NestedIOException;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;

/**
Expand Down Expand Up @@ -113,16 +112,14 @@ public File getFile() throws IOException {
* 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit d22c8ac

Please sign in to comment.