mirror of https://github.com/apache/poi.git
#64350 - Sonar fix - "Iterator.next()" methods should throw "NoSuchElementException"
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876525 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fde6f81305
commit
d06de78703
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.poi.hssf.record.aggregates;
|
package org.apache.poi.hssf.record.aggregates;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.apache.poi.hssf.model.RecordStream;
|
import org.apache.poi.hssf.model.RecordStream;
|
||||||
import org.apache.poi.hssf.record.BlankRecord;
|
import org.apache.poi.hssf.record.BlankRecord;
|
||||||
|
@ -338,8 +339,9 @@ public final class ValueRecordsAggregate implements Iterable<CellValueRecordInte
|
||||||
}
|
}
|
||||||
|
|
||||||
public CellValueRecordInterface next() {
|
public CellValueRecordInterface next() {
|
||||||
if (!hasNext())
|
if (!hasNext()) {
|
||||||
throw new IndexOutOfBoundsException("iterator has no next");
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
|
||||||
curRowIndex = nextRowIndex;
|
curRowIndex = nextRowIndex;
|
||||||
curColIndex = nextColIndex;
|
curColIndex = nextColIndex;
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.poi.hpsf.ClassID;
|
import org.apache.poi.hpsf.ClassID;
|
||||||
|
@ -213,6 +214,10 @@ public class FilteringDirectoryNode implements DirectoryEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry next() {
|
public Entry next() {
|
||||||
|
if (!hasNext()) {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
|
||||||
Entry e = next;
|
Entry e = next;
|
||||||
locateNext();
|
locateNext();
|
||||||
return e;
|
return e;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
import org.apache.poi.poifs.property.RootProperty;
|
import org.apache.poi.poifs.property.RootProperty;
|
||||||
|
@ -68,9 +69,7 @@ public class POIFSMiniStore extends BlockStore
|
||||||
it.next();
|
it.next();
|
||||||
}
|
}
|
||||||
ByteBuffer dataBlock = it.next();
|
ByteBuffer dataBlock = it.next();
|
||||||
if(dataBlock == null) {
|
assert(dataBlock != null);
|
||||||
throw new IndexOutOfBoundsException("Big block " + bigBlockNumber + " outside stream");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Position ourselves, and take a slice
|
// Position ourselves, and take a slice
|
||||||
dataBlock.position(
|
dataBlock.position(
|
||||||
|
@ -94,7 +93,7 @@ public class POIFSMiniStore extends BlockStore
|
||||||
if (! firstInStore) {
|
if (! firstInStore) {
|
||||||
try {
|
try {
|
||||||
return getBlockAt(offset);
|
return getBlockAt(offset);
|
||||||
} catch(IndexOutOfBoundsException e) {}
|
} catch(NoSuchElementException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to extend the stream
|
// Need to extend the stream
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
import org.apache.poi.poifs.filesystem.BlockStore.ChainLoopDetector;
|
import org.apache.poi.poifs.filesystem.BlockStore.ChainLoopDetector;
|
||||||
|
@ -157,8 +158,8 @@ public class POIFSStream implements Iterable<ByteBuffer>
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer next() {
|
public ByteBuffer next() {
|
||||||
if(nextBlock == POIFSConstants.END_OF_CHAIN) {
|
if (!hasNext()) {
|
||||||
throw new IndexOutOfBoundsException("Can't read past the end of the stream");
|
throw new NoSuchElementException("Can't read past the end of the stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.poi.util;
|
package org.apache.poi.util;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
// based on https://gist.github.com/EmmanuelOga/48df70b27ead4d80234b
|
// based on https://gist.github.com/EmmanuelOga/48df70b27ead4d80234b
|
||||||
@Internal
|
@Internal
|
||||||
|
@ -37,6 +38,9 @@ public class StringCodepointsIterable implements Iterable<String> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String next() {
|
public String next() {
|
||||||
|
if (!hasNext()) {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
int codePoint = StringCodepointsIterable.this.string.codePointAt(index);
|
int codePoint = StringCodepointsIterable.this.string.codePointAt(index);
|
||||||
index += Character.charCount(codePoint);
|
index += Character.charCount(codePoint);
|
||||||
return new String(Character.toChars(codePoint));
|
return new String(Character.toChars(codePoint));
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
|
|
||||||
package org.apache.poi.util;
|
package org.apache.poi.util;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.ISO_8859_1;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,7 +28,6 @@ import java.util.Locale;
|
||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
public final class StringUtil {
|
public final class StringUtil {
|
||||||
private static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1;
|
|
||||||
//arbitrarily selected; may need to increase
|
//arbitrarily selected; may need to increase
|
||||||
private static final int MAX_RECORD_LENGTH = 10000000;
|
private static final int MAX_RECORD_LENGTH = 10000000;
|
||||||
|
|
||||||
|
@ -305,38 +305,6 @@ public final class StringUtil {
|
||||||
return haystack.regionMatches(true, start, suffix, 0, length);
|
return haystack.regionMatches(true, start, suffix, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* An Iterator over an array of Strings.
|
|
||||||
*/
|
|
||||||
public static class StringsIterator implements Iterator<String> {
|
|
||||||
private String[] strings = {};
|
|
||||||
private int position;
|
|
||||||
|
|
||||||
public StringsIterator(String[] strings) {
|
|
||||||
if (strings != null) {
|
|
||||||
this.strings = strings.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return position < strings.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String next() {
|
|
||||||
int ourPos = position++;
|
|
||||||
if (ourPos >= strings.length) {
|
|
||||||
throw new ArrayIndexOutOfBoundsException(ourPos);
|
|
||||||
}
|
|
||||||
return strings[ourPos];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
public static String toLowerCase(char c) {
|
public static String toLowerCase(char c) {
|
||||||
return Character.toString(c).toLowerCase(Locale.ROOT);
|
return Character.toString(c).toLowerCase(Locale.ROOT);
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.apache.poi.common.usermodel.GenericRecord;
|
import org.apache.poi.common.usermodel.GenericRecord;
|
||||||
|
@ -172,6 +173,9 @@ public class HemfComment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EmfCommentData next() {
|
public EmfCommentData next() {
|
||||||
|
if (!hasNext()) {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
EmfCommentData toReturn = currentRecord;
|
EmfCommentData toReturn = currentRecord;
|
||||||
final boolean isEOF = (limit == -1 || leis.getReadIndex() >= startIdx+limit);
|
final boolean isEOF = (limit == -1 || leis.getReadIndex() >= startIdx+limit);
|
||||||
// (currentRecord instanceof HemfPlusMisc.EmfEof)
|
// (currentRecord instanceof HemfPlusMisc.EmfEof)
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.poi.hemf.record.emf;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndianConsts;
|
import org.apache.poi.util.LittleEndianConsts;
|
||||||
import org.apache.poi.util.LittleEndianInputStream;
|
import org.apache.poi.util.LittleEndianInputStream;
|
||||||
|
@ -44,6 +45,9 @@ public class HemfRecordIterator implements Iterator<HemfRecord> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HemfRecord next() {
|
public HemfRecord next() {
|
||||||
|
if (!hasNext()) {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
HemfRecord toReturn = currentRecord;
|
HemfRecord toReturn = currentRecord;
|
||||||
currentRecord = (currentRecord instanceof HemfMisc.EmfEof) ? null : _next();
|
currentRecord = (currentRecord instanceof HemfMisc.EmfEof) ? null : _next();
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.poi.hemf.record.emfplus;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndianInputStream;
|
import org.apache.poi.util.LittleEndianInputStream;
|
||||||
import org.apache.poi.util.RecordFormatException;
|
import org.apache.poi.util.RecordFormatException;
|
||||||
|
@ -49,6 +50,9 @@ public class HemfPlusRecordIterator implements Iterator<HemfPlusRecord> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HemfPlusRecord next() {
|
public HemfPlusRecord next() {
|
||||||
|
if (!hasNext()) {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
HemfPlusRecord toReturn = currentRecord;
|
HemfPlusRecord toReturn = currentRecord;
|
||||||
// add the size for recordId/flags/recordSize/dataSize = 12 bytes
|
// add the size for recordId/flags/recordSize/dataSize = 12 bytes
|
||||||
final boolean isEOF = (limit == -1 || (leis.getReadIndex()-startIdx)+12 > limit);
|
final boolean isEOF = (limit == -1 || (leis.getReadIndex()-startIdx)+12 > limit);
|
||||||
|
|
|
@ -16,6 +16,17 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hsmf.extractor;
|
package org.apache.poi.hsmf.extractor;
|
||||||
|
|
||||||
|
import static org.apache.poi.util.StringUtil.startsWithIgnoreCase;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.poi.extractor.POIOLE2TextExtractor;
|
import org.apache.poi.extractor.POIOLE2TextExtractor;
|
||||||
import org.apache.poi.hsmf.MAPIMessage;
|
import org.apache.poi.hsmf.MAPIMessage;
|
||||||
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
|
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
|
||||||
|
@ -24,16 +35,6 @@ import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.util.LocaleUtil;
|
import org.apache.poi.util.LocaleUtil;
|
||||||
import org.apache.poi.util.Removal;
|
|
||||||
import org.apache.poi.util.StringUtil.StringsIterator;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static org.apache.poi.util.StringUtil.startsWithIgnoreCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A text extractor for HSMF (Outlook) .msg files.
|
* A text extractor for HSMF (Outlook) .msg files.
|
||||||
|
@ -90,13 +91,11 @@ public class OutlookTextExtractor extends POIOLE2TextExtractor {
|
||||||
msg.guess7BitEncoding();
|
msg.guess7BitEncoding();
|
||||||
|
|
||||||
// Off we go
|
// Off we go
|
||||||
StringsIterator emails;
|
Iterator<String> emails;
|
||||||
try {
|
try {
|
||||||
emails = new StringsIterator(
|
emails = Arrays.asList(msg.getRecipientEmailAddressList()).iterator();
|
||||||
msg.getRecipientEmailAddressList()
|
|
||||||
);
|
|
||||||
} catch (ChunkNotFoundException e) {
|
} catch (ChunkNotFoundException e) {
|
||||||
emails = new StringsIterator(new String[0]);
|
emails = Collections.emptyIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -174,7 +173,7 @@ public class OutlookTextExtractor extends POIOLE2TextExtractor {
|
||||||
* of emails, and does its best to return something like
|
* of emails, and does its best to return something like
|
||||||
* "Nick <nick@example.com>; Jim <jim@example.com>"
|
* "Nick <nick@example.com>; Jim <jim@example.com>"
|
||||||
*/
|
*/
|
||||||
protected void handleEmails(StringBuilder s, String type, String displayText, StringsIterator emails) {
|
protected void handleEmails(StringBuilder s, String type, String displayText, Iterator<String> emails) {
|
||||||
if (displayText == null || displayText.length() == 0) {
|
if (displayText == null || displayText.length() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,18 +18,23 @@
|
||||||
|
|
||||||
package org.apache.poi.poifs.filesystem;
|
package org.apache.poi.poifs.filesystem;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to test FilteringDirectoryNode functionality
|
* Class to test FilteringDirectoryNode functionality
|
||||||
*/
|
*/
|
||||||
|
@ -72,12 +77,16 @@ public final class TestFilteringDirectoryNode {
|
||||||
assertEquals(dirA, i.next());
|
assertEquals(dirA, i.next());
|
||||||
assertEquals(dirB, i.next());
|
assertEquals(dirB, i.next());
|
||||||
assertEquals(eRoot, i.next());
|
assertEquals(eRoot, i.next());
|
||||||
|
try {
|
||||||
assertNull(i.next());
|
assertNull(i.next());
|
||||||
|
fail("Should throw NoSuchElementException when depleted");
|
||||||
|
} catch (NoSuchElementException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChildFiltering() throws Exception {
|
public void testChildFiltering() throws Exception {
|
||||||
List<String> excl = Arrays.asList(new String[]{"NotThere", "AlsoNotThere", eRoot.getName()});
|
List<String> excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName());
|
||||||
FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), excl);
|
FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), excl);
|
||||||
|
|
||||||
assertEquals(2, d.getEntryCount());
|
assertEquals(2, d.getEntryCount());
|
||||||
|
@ -96,11 +105,15 @@ public final class TestFilteringDirectoryNode {
|
||||||
Iterator<Entry> i = d.getEntries();
|
Iterator<Entry> i = d.getEntries();
|
||||||
assertEquals(dirA, i.next());
|
assertEquals(dirA, i.next());
|
||||||
assertEquals(dirB, i.next());
|
assertEquals(dirB, i.next());
|
||||||
|
try {
|
||||||
assertNull(i.next());
|
assertNull(i.next());
|
||||||
|
fail("Should throw NoSuchElementException when depleted");
|
||||||
|
} catch (NoSuchElementException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Filter more
|
// Filter more
|
||||||
excl = Arrays.asList(new String[]{"NotThere", "AlsoNotThere", eRoot.getName(), dirA.getName()});
|
excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName(), dirA.getName());
|
||||||
d = new FilteringDirectoryNode(fs.getRoot(), excl);
|
d = new FilteringDirectoryNode(fs.getRoot(), excl);
|
||||||
|
|
||||||
assertEquals(1, d.getEntryCount());
|
assertEquals(1, d.getEntryCount());
|
||||||
|
@ -122,11 +135,15 @@ public final class TestFilteringDirectoryNode {
|
||||||
|
|
||||||
i = d.getEntries();
|
i = d.getEntries();
|
||||||
assertEquals(dirB, i.next());
|
assertEquals(dirB, i.next());
|
||||||
|
try {
|
||||||
assertNull(i.next());
|
assertNull(i.next());
|
||||||
|
fail("Should throw NoSuchElementException when depleted");
|
||||||
|
} catch (NoSuchElementException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Filter everything
|
// Filter everything
|
||||||
excl = Arrays.asList(new String[]{"NotThere", eRoot.getName(), dirA.getName(), dirB.getName()});
|
excl = Arrays.asList("NotThere", eRoot.getName(), dirA.getName(), dirB.getName());
|
||||||
d = new FilteringDirectoryNode(fs.getRoot(), excl);
|
d = new FilteringDirectoryNode(fs.getRoot(), excl);
|
||||||
|
|
||||||
assertEquals(0, d.getEntryCount());
|
assertEquals(0, d.getEntryCount());
|
||||||
|
@ -151,17 +168,19 @@ public final class TestFilteringDirectoryNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
i = d.getEntries();
|
i = d.getEntries();
|
||||||
|
try {
|
||||||
assertNull(i.next());
|
assertNull(i.next());
|
||||||
|
fail("Should throw NoSuchElementException when depleted");
|
||||||
|
} catch (NoSuchElementException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNestedFiltering() throws Exception {
|
public void testNestedFiltering() throws Exception {
|
||||||
List<String> excl = Arrays.asList(new String[]{
|
List<String> excl = Arrays.asList(dirA.getName() + "/" + "MadeUp",
|
||||||
dirA.getName() + "/" + "MadeUp",
|
|
||||||
dirA.getName() + "/" + eA.getName(),
|
dirA.getName() + "/" + eA.getName(),
|
||||||
dirA.getName() + "/" + dirAA.getName() + "/Test",
|
dirA.getName() + "/" + dirAA.getName() + "/Test",
|
||||||
eRoot.getName()
|
eRoot.getName());
|
||||||
});
|
|
||||||
FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), excl);
|
FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), excl);
|
||||||
|
|
||||||
// Check main
|
// Check main
|
||||||
|
|
|
@ -26,6 +26,7 @@ import static org.junit.Assert.fail;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
|
@ -289,7 +290,7 @@ public final class TestPOIFSMiniStore {
|
||||||
try {
|
try {
|
||||||
ministore.getBlockAt(184);
|
ministore.getBlockAt(184);
|
||||||
fail("No block at 184");
|
fail("No block at 184");
|
||||||
} catch(IndexOutOfBoundsException e) {}
|
} catch(NoSuchElementException e) {}
|
||||||
|
|
||||||
// The ministore itself is made up of 23 big blocks
|
// The ministore itself is made up of 23 big blocks
|
||||||
Iterator<ByteBuffer> it = new POIFSStream(fs, fs.getRoot().getProperty().getStartBlock()).getBlockIterator();
|
Iterator<ByteBuffer> it = new POIFSStream(fs, fs.getRoot().getProperty().getStartBlock()).getBlockIterator();
|
||||||
|
@ -319,7 +320,7 @@ public final class TestPOIFSMiniStore {
|
||||||
try {
|
try {
|
||||||
ministore.getBlockAt(192);
|
ministore.getBlockAt(192);
|
||||||
fail("No block at 192");
|
fail("No block at 192");
|
||||||
} catch(IndexOutOfBoundsException e) {}
|
} catch(NoSuchElementException e) {}
|
||||||
|
|
||||||
|
|
||||||
// Now try writing through to 192, check that the SBAT and blocks are there
|
// Now try writing through to 192, check that the SBAT and blocks are there
|
||||||
|
|
|
@ -36,6 +36,7 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
||||||
|
@ -72,12 +73,8 @@ public final class TestPOIFSStream {
|
||||||
POIFSStream stream = new POIFSStream(fs, 98);
|
POIFSStream stream = new POIFSStream(fs, 98);
|
||||||
Iterator<ByteBuffer> i = stream.getBlockIterator();
|
Iterator<ByteBuffer> i = stream.getBlockIterator();
|
||||||
assertTrue(i.hasNext());
|
assertTrue(i.hasNext());
|
||||||
assertTrue(i.hasNext());
|
|
||||||
assertTrue(i.hasNext());
|
|
||||||
ByteBuffer b = i.next();
|
ByteBuffer b = i.next();
|
||||||
assertFalse(i.hasNext());
|
assertFalse(i.hasNext());
|
||||||
assertFalse(i.hasNext());
|
|
||||||
assertFalse(i.hasNext());
|
|
||||||
|
|
||||||
// Check the contents
|
// Check the contents
|
||||||
assertEquals((byte)0x81, b.get());
|
assertEquals((byte)0x81, b.get());
|
||||||
|
@ -103,15 +100,10 @@ public final class TestPOIFSStream {
|
||||||
POIFSStream stream = new POIFSStream(fs, 97);
|
POIFSStream stream = new POIFSStream(fs, 97);
|
||||||
Iterator<ByteBuffer> i = stream.getBlockIterator();
|
Iterator<ByteBuffer> i = stream.getBlockIterator();
|
||||||
assertTrue(i.hasNext());
|
assertTrue(i.hasNext());
|
||||||
assertTrue(i.hasNext());
|
|
||||||
assertTrue(i.hasNext());
|
|
||||||
ByteBuffer b97 = i.next();
|
ByteBuffer b97 = i.next();
|
||||||
assertTrue(i.hasNext());
|
assertTrue(i.hasNext());
|
||||||
assertTrue(i.hasNext());
|
|
||||||
ByteBuffer b98 = i.next();
|
ByteBuffer b98 = i.next();
|
||||||
assertFalse(i.hasNext());
|
assertFalse(i.hasNext());
|
||||||
assertFalse(i.hasNext());
|
|
||||||
assertFalse(i.hasNext());
|
|
||||||
|
|
||||||
// Check the contents of the 1st block
|
// Check the contents of the 1st block
|
||||||
assertEquals((byte)0x01, b97.get());
|
assertEquals((byte)0x01, b97.get());
|
||||||
|
@ -169,18 +161,21 @@ public final class TestPOIFSStream {
|
||||||
|
|
||||||
// Check the contents
|
// Check the contents
|
||||||
// 1st block is at 0
|
// 1st block is at 0
|
||||||
|
assertNotNull(b0);
|
||||||
assertEquals((byte)0x9e, b0.get());
|
assertEquals((byte)0x9e, b0.get());
|
||||||
assertEquals((byte)0x75, b0.get());
|
assertEquals((byte)0x75, b0.get());
|
||||||
assertEquals((byte)0x97, b0.get());
|
assertEquals((byte)0x97, b0.get());
|
||||||
assertEquals((byte)0xf6, b0.get());
|
assertEquals((byte)0xf6, b0.get());
|
||||||
|
|
||||||
// 2nd block is at 1
|
// 2nd block is at 1
|
||||||
|
assertNotNull(b1);
|
||||||
assertEquals((byte)0x86, b1.get());
|
assertEquals((byte)0x86, b1.get());
|
||||||
assertEquals((byte)0x09, b1.get());
|
assertEquals((byte)0x09, b1.get());
|
||||||
assertEquals((byte)0x22, b1.get());
|
assertEquals((byte)0x22, b1.get());
|
||||||
assertEquals((byte)0xfb, b1.get());
|
assertEquals((byte)0xfb, b1.get());
|
||||||
|
|
||||||
// last block is at 89
|
// last block is at 89
|
||||||
|
assertNotNull(b22);
|
||||||
assertEquals((byte)0xfe, b22.get());
|
assertEquals((byte)0xfe, b22.get());
|
||||||
assertEquals((byte)0xff, b22.get());
|
assertEquals((byte)0xff, b22.get());
|
||||||
assertEquals((byte)0x00, b22.get());
|
assertEquals((byte)0x00, b22.get());
|
||||||
|
@ -204,18 +199,12 @@ public final class TestPOIFSStream {
|
||||||
POIFSStream stream = new POIFSStream(fs, 0);
|
POIFSStream stream = new POIFSStream(fs, 0);
|
||||||
Iterator<ByteBuffer> i = stream.getBlockIterator();
|
Iterator<ByteBuffer> i = stream.getBlockIterator();
|
||||||
assertTrue(i.hasNext());
|
assertTrue(i.hasNext());
|
||||||
assertTrue(i.hasNext());
|
|
||||||
assertTrue(i.hasNext());
|
|
||||||
ByteBuffer b0 = i.next();
|
ByteBuffer b0 = i.next();
|
||||||
assertTrue(i.hasNext());
|
assertTrue(i.hasNext());
|
||||||
assertTrue(i.hasNext());
|
|
||||||
ByteBuffer b1 = i.next();
|
ByteBuffer b1 = i.next();
|
||||||
assertTrue(i.hasNext());
|
assertTrue(i.hasNext());
|
||||||
assertTrue(i.hasNext());
|
|
||||||
ByteBuffer b2 = i.next();
|
ByteBuffer b2 = i.next();
|
||||||
assertFalse(i.hasNext());
|
assertFalse(i.hasNext());
|
||||||
assertFalse(i.hasNext());
|
|
||||||
assertFalse(i.hasNext());
|
|
||||||
|
|
||||||
// Check the contents of the 1st block
|
// Check the contents of the 1st block
|
||||||
assertEquals((byte)0x9E, b0.get());
|
assertEquals((byte)0x9E, b0.get());
|
||||||
|
@ -304,17 +293,12 @@ public final class TestPOIFSStream {
|
||||||
POIFSStream stream = new POIFSStream(ministore, 178);
|
POIFSStream stream = new POIFSStream(ministore, 178);
|
||||||
Iterator<ByteBuffer> i = stream.getBlockIterator();
|
Iterator<ByteBuffer> i = stream.getBlockIterator();
|
||||||
assertTrue(i.hasNext());
|
assertTrue(i.hasNext());
|
||||||
assertTrue(i.hasNext());
|
|
||||||
assertTrue(i.hasNext());
|
|
||||||
ByteBuffer b178 = i.next();
|
ByteBuffer b178 = i.next();
|
||||||
assertTrue(i.hasNext());
|
assertTrue(i.hasNext());
|
||||||
assertTrue(i.hasNext());
|
|
||||||
ByteBuffer b179 = i.next();
|
ByteBuffer b179 = i.next();
|
||||||
assertTrue(i.hasNext());
|
assertTrue(i.hasNext());
|
||||||
ByteBuffer b180 = i.next();
|
ByteBuffer b180 = i.next();
|
||||||
assertFalse(i.hasNext());
|
assertFalse(i.hasNext());
|
||||||
assertFalse(i.hasNext());
|
|
||||||
assertFalse(i.hasNext());
|
|
||||||
|
|
||||||
// Check the contents of the 1st block
|
// Check the contents of the 1st block
|
||||||
assertEquals((byte)0xfe, b178.get());
|
assertEquals((byte)0xfe, b178.get());
|
||||||
|
@ -803,7 +787,7 @@ public final class TestPOIFSStream {
|
||||||
try {
|
try {
|
||||||
ministore.getBlockAt(184);
|
ministore.getBlockAt(184);
|
||||||
fail("Block 184 should be off the end of the list");
|
fail("Block 184 should be off the end of the list");
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (NoSuchElementException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
data = new byte[64 * 6 + 12];
|
data = new byte[64 * 6 + 12];
|
||||||
|
|
|
@ -24,7 +24,6 @@ import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import org.apache.poi.util.StringUtil.StringsIterator;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,52 +126,6 @@ public class TestStringUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testStringsIterator() {
|
|
||||||
StringsIterator i;
|
|
||||||
|
|
||||||
|
|
||||||
i = new StringsIterator(new String[0]);
|
|
||||||
assertFalse(i.hasNext());
|
|
||||||
try {
|
|
||||||
i.next();
|
|
||||||
fail();
|
|
||||||
} catch(ArrayIndexOutOfBoundsException e) {
|
|
||||||
// expected here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
i = new StringsIterator(new String[] {"1"});
|
|
||||||
assertTrue(i.hasNext());
|
|
||||||
assertEquals("1", i.next());
|
|
||||||
|
|
||||||
assertFalse(i.hasNext());
|
|
||||||
try {
|
|
||||||
i.next();
|
|
||||||
fail();
|
|
||||||
} catch(ArrayIndexOutOfBoundsException e) {
|
|
||||||
// expected here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
i = new StringsIterator(new String[] {"1","2","3"});
|
|
||||||
assertTrue(i.hasNext());
|
|
||||||
assertEquals("1", i.next());
|
|
||||||
assertTrue(i.hasNext());
|
|
||||||
assertEquals("2", i.next());
|
|
||||||
assertTrue(i.hasNext());
|
|
||||||
assertEquals("3", i.next());
|
|
||||||
|
|
||||||
assertFalse(i.hasNext());
|
|
||||||
try {
|
|
||||||
i.next();
|
|
||||||
fail();
|
|
||||||
} catch(ArrayIndexOutOfBoundsException e) {
|
|
||||||
// expected here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void startsWithIgnoreCase() {
|
public void startsWithIgnoreCase() {
|
||||||
assertTrue("same string", StringUtil.startsWithIgnoreCase("Apache POI", "Apache POI"));
|
assertTrue("same string", StringUtil.startsWithIgnoreCase("Apache POI", "Apache POI"));
|
||||||
|
|
Loading…
Reference in New Issue