Interface SizeAwareDataSource

All Superinterfaces:
All Known Subinterfaces:
All Known Implementing Classes:
BlobDataSource, ByteArrayDataSource, CachedFileDataSource, EmptyDataSource

public interface SizeAwareDataSource
extends DataSource

Optional extension interface that can be implemented by data sources that support a getSize method. Code working with data sources can use this this information to optimize certain operations. Note however that instead of checking of this interface directly, this kind of code should use DataSourceUtils.getSize(DataSource) because this method is able to determine the size of other types of data sources as well.

Code using this interface should be aware that some implementations may be unable to guarantee 100% accuracy when determining the size of the data source. Situations where this can occur include:

When reading the actual data, the code should always read until the end of the stream is reached (as indicated by the return value of the read methods of the InputStream class). It must be prepared to reach the end of the stream after a number of bytes that is lower or higher than the value returned by getSize().

Method Summary
 long getSize()
          Get the size of the data source.
Methods inherited from interface javax.activation.DataSource
getContentType, getInputStream, getName, getOutputStream

Method Detail


long getSize()
Get the size of the data source. Implementations must return the number of bytes that can be read from the input stream returned by DataSource.getInputStream() before reaching the end of the stream. If the implementation is unable to determine the size, it must return -1.

the size of the data source or -1 if the size is not known

Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.