Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tika-app/src/main/java/org/apache/tika/cli/TikaCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public static void main(String[] args) throws Exception {
}

if (args.length > 0) {
for (int i = 0; i < args.length; i++) {
cli.process(args[i]);
for (String arg : args) {
cli.process(arg);
}
if (cli.pipeMode) {
cli.process("-");
Expand Down
4 changes: 2 additions & 2 deletions tika-core/src/main/java/org/apache/tika/fork/ForkClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ public synchronized Throwable call(String method, Object... args)
List<ForkResource> r = new ArrayList<>(resources);
output.writeByte(ForkServer.CALL);
output.writeUTF(method);
for (int i = 0; i < args.length; i++) {
sendObject(args[i], r);
for (Object arg : args) {
sendObject(arg, r);
}
return waitForResponse(r);
}
Expand Down
4 changes: 2 additions & 2 deletions tika-core/src/main/java/org/apache/tika/io/FilenameUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class FilenameUtils {


static {
for (int i=0; i<RESERVED_FILENAME_CHARACTERS.length; ++i) {
RESERVED.add(RESERVED_FILENAME_CHARACTERS[i]);
for (char reservedFilenameCharacter : RESERVED_FILENAME_CHARACTERS) {
RESERVED.add(reservedFilenameCharacter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ public void save(OutputStream os) throws IOException {
NGramEntry[] entries = ngrams.values().toArray(
new NGramEntry[ngrams.size()]);
for (int i = minLength; i <= maxLength; i++) {
for (int j = 0; j < entries.length; j++) {
if (entries[j].getSeq().length() == i) {
sublist.add(entries[j]);
for (NGramEntry entry : entries) {
if (entry.getSeq().length() == i) {
sublist.add(entry);
}
}
Collections.sort(sublist);
Expand All @@ -427,8 +427,7 @@ public void save(OutputStream os) throws IOException {
list.addAll(sublist);
sublist.clear();
}
for (int i = 0; i < list.size(); i++) {
NGramEntry e = list.get(i);
for (NGramEntry e : list) {
String line = e.toString() + " " + e.getCount() + "\n";
os.write(line.getBytes(UTF_8));
}
Expand Down
25 changes: 12 additions & 13 deletions tika-core/src/main/java/org/apache/tika/metadata/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,8 @@ public int size() {

public int hashCode() {
int h = 0;
for (Iterator<Entry<String,String[]>> i = metadata.entrySet().iterator();
i.hasNext();) {
h += getMetadataEntryHashCode(i.next());
for (Entry<String, String[]> stringEntry : metadata.entrySet()) {
h += getMetadataEntryHashCode(stringEntry);
}
return h;
}
Expand All @@ -534,9 +533,9 @@ public boolean equals(Object o) {
}

String[] names = names();
for (int i = 0; i < names.length; i++) {
String[] otherValues = other._getValues(names[i]);
String[] thisValues = _getValues(names[i]);
for (String name : names) {
String[] otherValues = other._getValues(name);
String[] thisValues = _getValues(name);
if (otherValues.length != thisValues.length) {
return false;
}
Expand All @@ -552,13 +551,13 @@ public boolean equals(Object o) {
public String toString() {
StringBuffer buf = new StringBuffer();
String[] names = names();
for (int i = 0; i < names.length; i++) {
String[] values = _getValues(names[i]);
for (int j = 0; j < values.length; j++) {
if (buf.length() > 0) {
buf.append(" ");
}
buf.append(names[i]).append("=").append(values[j]);
for (String name : names) {
String[] values = _getValues(name);
for (String value : values) {
if (buf.length() > 0) {
buf.append(" ");
}
buf.append(name).append("=").append(value);
}
}
return buf.toString();
Expand Down
6 changes: 2 additions & 4 deletions tika-core/src/main/java/org/apache/tika/mime/MimeTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,8 @@ private List<MimeType> applyHint(List<MimeType> possibleTypes, MimeType hint) {
if (possibleTypes == null || possibleTypes.isEmpty()) {
return Collections.singletonList(hint);
} else {
for (int i=0; i<possibleTypes.size(); i++) {
final MimeType type = possibleTypes.get(i);
if (hint.equals(type) ||
registry.isSpecializationOf(hint.getType(), type.getType())) {
for (final MimeType type : possibleTypes) {
if (hint.equals(type) || registry.isSpecializationOf(hint.getType(), type.getType())) {
// Use just this type
return Collections.singletonList(hint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static Metadata cloneMetadata(Metadata m) {
clone.set(n, m.get(n));
} else {
String[] vals = m.getValues(n);
for (int i = 0; i < vals.length; i++) {
clone.add(n, vals[i]);
for (String val : vals) {
clone.add(n, val);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ private void assertDetect(Detector detector, MediaType type, byte[] bytes) {
assertEquals(type, detector.detect(stream, new Metadata()));

// Test that the stream has been reset
for (int i = 0; i < bytes.length; i++) {
assertEquals(bytes[i], (byte) stream.read());
for (byte aByte : bytes) {
assertEquals(aByte, (byte) stream.read());
}
assertEquals(-1, stream.read());
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private void assertText(byte[] data) {
detector.detect(stream, new Metadata()));

// Test that the stream has been reset
for (int i = 0; i < data.length; i++) {
assertEquals(data[i], (byte) stream.read());
for (byte aByte : data) {
assertEquals(aByte, (byte) stream.read());
}
assertEquals(-1, stream.read());
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public void filter(Metadata metadata) throws TikaException {
for (String n : metadata.names()) {
String[] vals = metadata.getValues(n);
metadata.remove(n);
for (int i = 0; i < vals.length; i++) {
metadata.add(n, vals[i].toUpperCase(Locale.US));
for (String val : vals) {
metadata.add(n, val.toUpperCase(Locale.US));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ public List<Metadata> loadExtract(Path extractFile) throws ExtractReaderExceptio
metadataList.size() > 1) {
StringBuilder sb = new StringBuilder();
Metadata containerMetadata = metadataList.get(0);
for (int i = 0; i < metadataList.size(); i++) {
Metadata m = metadataList.get(i);
for (Metadata m : metadataList) {
String c = m.get(AbstractRecursiveParserWrapperHandler.TIKA_CONTENT);
if (c != null) {
sb.append(c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ public static void tearDown() throws IOException {


DirectoryStream<Path> dStream = Files.newDirectoryStream(dbDir);
Iterator<Path> it = dStream.iterator();
while (it.hasNext()) {
Path p = it.next();
for (Path p : dStream) {
Files.delete(p);
}
dStream.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public String generateRSS(Path indexFile) throws CorruptIndexException,
TopScoreDocCollector collector = TopScoreDocCollector.create(20,10000);
searcher.search(query, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
for (int i = 0; i < hits.length; i++) {
Document doc = searcher.doc(hits[i].doc);
for (ScoreDoc hit : hits) {
Document doc = searcher.doc(hit.doc);
output.append(getRSSItem(doc));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public void transform(InputStream is, OutputStream os) throws IOException, TikaE
//TODO -- make this actually streaming
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copy(is, bos);
for (int i = 0; i < transformerIndices.length; i++) {
for (int transformerIndex : transformerIndices) {
byte[] bytes = bos.toByteArray();
bos = new ByteArrayOutputStream();
transformers[transformerIndices[i]].transform(
transformers[transformerIndex].transform(
new ByteArrayInputStream(bytes), bos);
bos.flush();
if (bos.toByteArray().length == 0) {
LOG.warn("zero length: "+transformers[transformerIndices[i]]);
LOG.warn("zero length: " + transformers[transformerIndex]);
}
}
os.write(bos.toByteArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ public void addText(char[] cbuf, int off, int len) {
public List<LanguageResult> detectAll() {
Language[] langs = detector.predictLanguages(buffer.toString());
List<LanguageResult> results = new ArrayList<>();
for (int i = 0; i < langs.length; i++) {
LanguageResult r = new LanguageResult(langs[i].getLang(), getConfidence(langs[i].getConfidence()),
(float)langs[i].getConfidence());
for (Language lang : langs) {
LanguageResult r = new LanguageResult(lang.getLang(), getConfidence(lang.getConfidence()),
(float) lang.getConfidence());
results.add(r);
}
return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ private List<TSDMetas> extractMetas(InputStream stream) {

TimeStampToken[] tokens = cmsTimeStampedData.getTimeStampTokens();

for (int i = 0; i < tokens.length; i++) {
for (TimeStampToken token : tokens) {
TSDMetas tsdMetas = new TSDMetas(true,
tokens[i].getTimeStampInfo().getGenTime(),
tokens[i].getTimeStampInfo().getPolicy().getId(),
tokens[i].getTimeStampInfo().getSerialNumber(),
tokens[i].getTimeStampInfo().getTsa(),
tokens[i].getTimeStampInfo().getHashAlgorithm().getAlgorithm().getId());
token.getTimeStampInfo().getGenTime(),
token.getTimeStampInfo().getPolicy().getId(),
token.getTimeStampInfo().getSerialNumber(),
token.getTimeStampInfo().getTsa(),
token.getTimeStampInfo().getHashAlgorithm().getAlgorithm().getId());

tsdMetasList.add(tsdMetas);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public void testXMLProfiler() throws Exception {
int xmlProfilers = 0;
for (Metadata metadata : metadataList) {
String[] parsedBy = metadata.getValues("X-Parsed-By");
for (int i = 0; i < parsedBy.length; i++) {
if (parsedBy[i].equals(XMLProfiler.class.getCanonicalName())) {
for (String s : parsedBy) {
if (s.equals(XMLProfiler.class.getCanonicalName())) {
xmlProfilers++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ public void parse(Database db, XHTMLContentHandler xhtml) throws IOException, SA

}

Iterator<Table> it = db.newIterable().
setIncludeLinkedTables(false).
setIncludeSystemTables(false).iterator();

while (it.hasNext()) {
Table table = it.next();
for (Table table : db.newIterable().setIncludeLinkedTables(false).setIncludeSystemTables(false)) {
String tableName = table.getName();
List<? extends Column> columns = table.getColumns();
xhtml.startElement("table", "name", tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ private String convertToNewNumberText(String numberText, byte[] numberOffsets) {

StringBuilder sb = new StringBuilder();
int last = 0;
for (int i = 0; i < numberOffsets.length; i++) {
int offset = (int) numberOffsets[i];
for (byte numberOffset : numberOffsets) {
int offset = (int) numberOffset;

if (offset == 0) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ private static POIXMLTextExtractor tryXSLF(OPCPackage pkg, boolean eventBased) t

XSLFRelation[] xslfRelations = org.apache.poi.xslf.extractor.XSLFPowerPointExtractor.SUPPORTED_TYPES;

for (int i = 0; i < xslfRelations.length; i++) {
XSLFRelation xslfRelation = xslfRelations[i];
for (XSLFRelation xslfRelation : xslfRelations) {
if (xslfRelation.getContentType().equals(targetContentType)) {
if (eventBased) {
return new XSLFEventBasedPowerPointExtractor(pkg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,26 @@ protected void buildXHTML(XHTMLContentHandler xhtml) throws SAXException, IOExce
List<XSLFComment> comments = slide.getComments();
if (comments != null) {
StringBuilder authorStringBuilder = new StringBuilder();
for (int i = 0; i < comments.size(); i++) {
for (XSLFComment comment : comments) {
authorStringBuilder.setLength(0);
XSLFComment comment = comments.get(i);
xhtml.startElement("p", "class", "slide-comment");
if (comment.getAuthor() != null) {
authorStringBuilder.append(comment.getAuthor());
}
if (comment.getAuthorInitials() != null) {
if (authorStringBuilder.length() > 0) {
authorStringBuilder.append(" ");
}
authorStringBuilder.append("("+comment.getAuthorInitials()+")");
}
if (comment.getText() != null && authorStringBuilder.length() > 0) {
authorStringBuilder.append(" - ");
}
if (comment.getAuthor() != null) {
authorStringBuilder.append(comment.getAuthor());
}
if (comment.getAuthorInitials() != null) {
if (authorStringBuilder.length() > 0) {
xhtml.startElement("b");
xhtml.characters(authorStringBuilder.toString());
xhtml.endElement("b");
authorStringBuilder.append(" ");
}
authorStringBuilder.append("(" + comment.getAuthorInitials() + ")");
}
if (comment.getText() != null && authorStringBuilder.length() > 0) {
authorStringBuilder.append(" - ");
}
if (authorStringBuilder.length() > 0) {
xhtml.startElement("b");
xhtml.characters(authorStringBuilder.toString());
xhtml.endElement("b");
}

xhtml.characters(comment.getText());
xhtml.endElement("p");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ private boolean fillRow(DBFRow row) throws IOException, TikaException {
row.setDeleted(isDeleted);

boolean readSomeContent = false;
for (int i = 0; i < cells.length; i++) {
if (cells[i].read(is)) {
for (DBFCell cell : cells) {
if (cell.read(is)) {
readSomeContent = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ public int getDepth() {
*/
public void setDepth(int depth) {
int[] allowedValues = {2, 4, 8, 16, 32, 64, 256, 4096};
for (int i = 0; i < allowedValues.length; i++) {
if (depth == allowedValues[i]) {
for (int allowedValue : allowedValues) {
if (depth == allowedValue) {
this.depth = depth;
return;
}
Expand Down Expand Up @@ -493,8 +493,8 @@ public void setFilter(String filter) {
}

String[] allowedFilters = {"Point", "Hermite", "Cubic", "Box", "Gaussian", "Catrom", "Triangle", "Quadratic", "Mitchell"};
for (int i = 0; i < allowedFilters.length; i++) {
if (filter.equalsIgnoreCase(allowedFilters[i])) {
for (String allowedFilter : allowedFilters) {
if (filter.equalsIgnoreCase(allowedFilter)) {
this.filter = filter;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ public List<CaptionObject> recognise(InputStream stream,
if (response.getStatusLine().getStatusCode() == 200) {
JSONObject jReply = (JSONObject) new JSONParser().parse(replyMessage);
JSONArray jCaptions = (JSONArray) jReply.get("captions");
for (int i = 0; i < jCaptions.size(); i++) {
JSONObject jCaption = (JSONObject) jCaptions.get(i);
for (Object caption : jCaptions) {
JSONObject jCaption = (JSONObject) caption;
String sentence = (String) jCaption.get("sentence");
Double confidence = (Double) jCaption.get("confidence");
capObjs.add(new CaptionObject(sentence, LABEL_LANG, confidence));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ public void endDocument() throws SAXException {
metadata.add(CTAKES_META_PREFIX + "schema", config.getAnnotationPropsAsString());
CTAKESAnnotationProperty[] annotationPros = config.getAnnotationProps();
Collection<IdentifiedAnnotation> collection = JCasUtil.select(jcas, IdentifiedAnnotation.class);
Iterator<IdentifiedAnnotation> iterator = collection.iterator();
while (iterator.hasNext()) {
IdentifiedAnnotation annotation = iterator.next();
for (IdentifiedAnnotation annotation : collection) {
StringBuilder annotationBuilder = new StringBuilder();
annotationBuilder.append(annotation.getCoveredText());
if (annotationPros != null) {
Expand Down
Loading