Fix inconsistent whitespace

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1590190 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2014-04-25 23:33:16 +00:00
parent c3769b5da0
commit b77ce4fede

View File

@ -29,147 +29,147 @@ import org.apache.poi.util.LittleEndian;
* {@link NPOIFSFileSystem} instance. * {@link NPOIFSFileSystem} instance.
*/ */
public final class NDocumentInputStream extends DocumentInputStream { public final class NDocumentInputStream extends DocumentInputStream {
/** current offset into the Document */ /** current offset into the Document */
private int _current_offset; private int _current_offset;
/** current block count */ /** current block count */
private int _current_block_count; private int _current_block_count;
/** current marked offset into the Document (used by mark and reset) */ /** current marked offset into the Document (used by mark and reset) */
private int _marked_offset; private int _marked_offset;
/** and the block count for it */ /** and the block count for it */
private int _marked_offset_count; private int _marked_offset_count;
/** the Document's size */ /** the Document's size */
private int _document_size; private int _document_size;
/** have we been closed? */ /** have we been closed? */
private boolean _closed; private boolean _closed;
/** the actual Document */ /** the actual Document */
private NPOIFSDocument _document; private NPOIFSDocument _document;
private Iterator<ByteBuffer> _data;
private ByteBuffer _buffer;
/** private Iterator<ByteBuffer> _data;
* Create an InputStream from the specified DocumentEntry private ByteBuffer _buffer;
*
* @param document the DocumentEntry to be read
*
* @exception IOException if the DocumentEntry cannot be opened (like, maybe it has
* been deleted?)
*/
public NDocumentInputStream(DocumentEntry document) throws IOException {
if (!(document instanceof DocumentNode)) {
throw new IOException("Cannot open internal document storage, " + document + " not a Document Node");
}
_current_offset = 0;
_current_block_count = 0;
_marked_offset = 0;
_marked_offset_count = 0;
_document_size = document.getSize();
_closed = false;
DocumentNode doc = (DocumentNode)document;
DocumentProperty property = (DocumentProperty)doc.getProperty();
_document = new NPOIFSDocument(
property,
((DirectoryNode)doc.getParent()).getNFileSystem()
);
_data = _document.getBlockIterator();
}
/** /**
* Create an InputStream from the specified Document * Create an InputStream from the specified DocumentEntry
* *
* @param document the Document to be read * @param document the DocumentEntry to be read
*/ *
public NDocumentInputStream(NPOIFSDocument document) { * @exception IOException if the DocumentEntry cannot be opened (like, maybe it has
_current_offset = 0; * been deleted?)
_current_block_count = 0; */
_marked_offset = 0; public NDocumentInputStream(DocumentEntry document) throws IOException {
_marked_offset_count = 0; if (!(document instanceof DocumentNode)) {
_document_size = document.getSize(); throw new IOException("Cannot open internal document storage, " + document + " not a Document Node");
_closed = false; }
_document = document; _current_offset = 0;
_data = _document.getBlockIterator(); _current_block_count = 0;
} _marked_offset = 0;
_marked_offset_count = 0;
_document_size = document.getSize();
_closed = false;
@Override DocumentNode doc = (DocumentNode)document;
public int available() { DocumentProperty property = (DocumentProperty)doc.getProperty();
if (_closed) { _document = new NPOIFSDocument(
throw new IllegalStateException("cannot perform requested operation on a closed stream"); property,
} ((DirectoryNode)doc.getParent()).getNFileSystem()
return _document_size - _current_offset; );
} _data = _document.getBlockIterator();
}
@Override /**
public void close() { * Create an InputStream from the specified Document
_closed = true; *
} * @param document the Document to be read
*/
public NDocumentInputStream(NPOIFSDocument document) {
_current_offset = 0;
_current_block_count = 0;
_marked_offset = 0;
_marked_offset_count = 0;
_document_size = document.getSize();
_closed = false;
_document = document;
_data = _document.getBlockIterator();
}
@Override @Override
public void mark(int ignoredReadlimit) { public int available() {
_marked_offset = _current_offset; if (_closed) {
_marked_offset_count = Math.max(0, _current_block_count - 1); throw new IllegalStateException("cannot perform requested operation on a closed stream");
} }
return _document_size - _current_offset;
}
@Override @Override
public int read() throws IOException { public void close() {
dieIfClosed(); _closed = true;
if (atEOD()) { }
return EOF;
}
byte[] b = new byte[1];
int result = read(b, 0, 1);
if(result >= 0) {
if(b[0] < 0) {
return b[0]+256;
}
return b[0];
}
return result;
}
@Override @Override
public int read(byte[] b, int off, int len) throws IOException { public void mark(int ignoredReadlimit) {
dieIfClosed(); _marked_offset = _current_offset;
if (b == null) { _marked_offset_count = Math.max(0, _current_block_count - 1);
throw new IllegalArgumentException("buffer must not be null"); }
}
if (off < 0 || len < 0 || b.length < off + len) {
throw new IndexOutOfBoundsException("can't read past buffer boundaries");
}
if (len == 0) {
return 0;
}
if (atEOD()) {
return EOF;
}
int limit = Math.min(available(), len);
readFully(b, off, limit);
return limit;
}
/** @Override
* Repositions this stream to the position at the time the mark() method was public int read() throws IOException {
* last called on this input stream. If mark() has not been called this dieIfClosed();
* method repositions the stream to its beginning. if (atEOD()) {
*/ return EOF;
@Override }
public void reset() { byte[] b = new byte[1];
// Special case for reset to the start int result = read(b, 0, 1);
if(_marked_offset == 0 && _marked_offset_count == 0) { if(result >= 0) {
_current_block_count = _marked_offset_count; if(b[0] < 0) {
_current_offset = _marked_offset; return b[0]+256;
_data = _document.getBlockIterator(); }
_buffer = null; return b[0];
return; }
} return result;
}
// Start again, then wind on to the required block
_data = _document.getBlockIterator(); @Override
_current_offset = 0; public int read(byte[] b, int off, int len) throws IOException {
dieIfClosed();
if (b == null) {
throw new IllegalArgumentException("buffer must not be null");
}
if (off < 0 || len < 0 || b.length < off + len) {
throw new IndexOutOfBoundsException("can't read past buffer boundaries");
}
if (len == 0) {
return 0;
}
if (atEOD()) {
return EOF;
}
int limit = Math.min(available(), len);
readFully(b, off, limit);
return limit;
}
/**
* Repositions this stream to the position at the time the mark() method was
* last called on this input stream. If mark() has not been called this
* method repositions the stream to its beginning.
*/
@Override
public void reset() {
// Special case for reset to the start
if(_marked_offset == 0 && _marked_offset_count == 0) {
_current_block_count = _marked_offset_count;
_current_offset = _marked_offset;
_data = _document.getBlockIterator();
_buffer = null;
return;
}
// Start again, then wind on to the required block
_data = _document.getBlockIterator();
_current_offset = 0;
for(int i=0; i<_marked_offset_count; i++) { for(int i=0; i<_marked_offset_count; i++) {
_buffer = _data.next(); _buffer = _data.next();
_current_offset += _buffer.remaining(); _current_offset += _buffer.remaining();