This is an automated email from the ASF dual-hosted git repository. dsmiley pushed a commit to branch branch_10x in repository https://gitbox.apache.org/repos/asf/solr.git
commit 6125fb2d412d98614bd3f12d39080a46c759eabc Author: Eric Pugh <[email protected]> AuthorDate: Fri Jul 31 20:02:38 2026 -0400 Tidy up java code in o.a.s.i.csv package (#4681) (cherry picked from commit c9ed84e97864f19cc0f80a80100648855e527752) --- .../org/apache/solr/internal/csv/CSVParser.java | 19 ++++------- .../org/apache/solr/internal/csv/CSVPrinter.java | 38 ---------------------- .../org/apache/solr/internal/csv/CSVStrategy.java | 8 ++--- .../org/apache/solr/internal/csv/CSVUtils.java | 36 +------------------- .../solr/internal/csv/ExtendedBufferedReader.java | 20 ++++++------ .../java/org/apache/solr/logging/LogWatcher.java | 4 +-- .../org/apache/solr/logging/jul/JulWatcher.java | 2 +- .../apache/solr/logging/log4j2/Log4j2Watcher.java | 2 +- 8 files changed, 24 insertions(+), 105 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/internal/csv/CSVParser.java b/solr/core/src/java/org/apache/solr/internal/csv/CSVParser.java index a5495a31106..3f22e6aefe5 100644 --- a/solr/core/src/java/org/apache/solr/internal/csv/CSVParser.java +++ b/solr/core/src/java/org/apache/solr/internal/csv/CSVParser.java @@ -254,14 +254,14 @@ public class CSVParser { * @throws IOException on stream access error */ protected Token nextToken(Token tkn) throws IOException { - wsBuf.clear(); // resuse + wsBuf.clear(); // reuse // get the last read char (required for empty line detection) int lastChar = in.readAgain(); // read the next char and set eol - /* note: unfortunately isEndOfLine may consumes a character silently. - * this has no effect outside of the method. so a simple workaround + /* note: unfortunately isEndOfLine may consume a character silently. + * this has no effect outside the method. so a simple workaround * is to call 'readAgain' on the stream... * uh: might using objects instead of base-types (jdk1.5 autoboxing!) */ @@ -286,7 +286,7 @@ public class CSVParser { } } - // did we reached eof during the last iteration already ? TT_EOF + // did we reach eof during the last iteration already ? TT_EOF if (isEndOfFile(lastChar) || (lastChar != strategy.getDelimiter() && isEndOfFile(c))) { tkn.type = TT_EOF; return tkn; @@ -302,7 +302,7 @@ public class CSVParser { } // ok, start of token reached: comment, encapsulated, or token if (c == strategy.getCommentStart()) { - // ignore everything till end of line and continue (incr linecount) + // ignore everything till end of line and continue (increment line count) in.readLine(); tkn = nextToken(tkn.reset()); } else if (c == strategy.getDelimiter()) { @@ -464,7 +464,7 @@ public class CSVParser { * * @param c current char which is discarded because it's the "\\" of "\\uXXXX" * @return the decoded character - * @throws IOException on wrong unicode escape sequence or read error + * @throws IOException on wrong Unicode escape sequence or read error */ protected int unicodeEscapeLexer(int c) throws IOException { int ret = 0; @@ -482,12 +482,7 @@ public class CSVParser { ret = Integer.parseInt(code.toString(), 16); } catch (NumberFormatException e) { throw new IOException( - "(line " - + getLineNumber() - + ") Wrong unicode escape sequence found '" - + code.toString() - + "'" - + e.toString()); + "(line " + getLineNumber() + ") Wrong unicode escape sequence found '" + code + "'" + e); } return ret; } diff --git a/solr/core/src/java/org/apache/solr/internal/csv/CSVPrinter.java b/solr/core/src/java/org/apache/solr/internal/csv/CSVPrinter.java index e759236a5c2..9e8c543a1ef 100644 --- a/solr/core/src/java/org/apache/solr/internal/csv/CSVPrinter.java +++ b/solr/core/src/java/org/apache/solr/internal/csv/CSVPrinter.java @@ -73,44 +73,6 @@ public class CSVPrinter { println(); } - /** - * Put a comment among the comma separated values. Comments will always begin on a new line and - * occupy a least one full line. The character specified to star comments and a space will be - * inserted at the beginning of each new line in the comment. - * - * @param comment the comment to output - */ - @SuppressWarnings({"fallthrough"}) - public void printlnComment(String comment) throws IOException { - if (this.strategy.isCommentingDisabled()) { - return; - } - if (!newLine) { - println(); - } - out.write(this.strategy.getCommentStart()); - out.write(' '); - for (int i = 0; i < comment.length(); i++) { - char c = comment.charAt(i); - switch (c) { - case '\r': - if (i + 1 < comment.length() && comment.charAt(i + 1) == '\n') { - i++; - } - // break intentionally excluded. - case '\n': - println(); - out.write(this.strategy.getCommentStart()); - out.write(' '); - break; - default: - out.write(c); - break; - } - } - println(); - } - public void print(char[] value, int offset, int len, boolean checkForEscape) throws IOException { if (!checkForEscape) { printSep(); diff --git a/solr/core/src/java/org/apache/solr/internal/csv/CSVStrategy.java b/solr/core/src/java/org/apache/solr/internal/csv/CSVStrategy.java index 98f2d6cbb58..c647bc6240c 100644 --- a/solr/core/src/java/org/apache/solr/internal/csv/CSVStrategy.java +++ b/solr/core/src/java/org/apache/solr/internal/csv/CSVStrategy.java @@ -102,8 +102,8 @@ public class CSVStrategy implements Cloneable, Serializable { * @param escape a Char used for escaping * @param ignoreTrailingWhitespaces TRUE when trailing whitespaces should be ignored * @param ignoreLeadingWhitespaces TRUE when leading whitespaces should be ignored - * @param interpretUnicodeEscapes TRUE when unicode escapes should be interpreted - * @param ignoreEmptyLines TRUE when the parser should skip emtpy lines + * @param interpretUnicodeEscapes TRUE when Unicode escapes should be interpreted + * @param ignoreEmptyLines TRUE when the parser should skip empty lines * @param printerNewline The string to use when printing a newline */ public CSVStrategy( @@ -139,10 +139,6 @@ public class CSVStrategy implements Cloneable, Serializable { return this.commentStart; } - public boolean isCommentingDisabled() { - return this.commentStart == COMMENTS_DISABLED; - } - public char getEscape() { return this.escape; } diff --git a/solr/core/src/java/org/apache/solr/internal/csv/CSVUtils.java b/solr/core/src/java/org/apache/solr/internal/csv/CSVUtils.java index 8bb0ad3703a..76c7922bc9b 100644 --- a/solr/core/src/java/org/apache/solr/internal/csv/CSVUtils.java +++ b/solr/core/src/java/org/apache/solr/internal/csv/CSVUtils.java @@ -18,7 +18,6 @@ package org.apache.solr.internal.csv; import java.io.IOException; import java.io.StringReader; -import java.io.StringWriter; /** Utility methods for dealing with CSV files */ public class CSVUtils { @@ -33,39 +32,6 @@ public class CSVUtils { */ public CSVUtils() {} - /** - * Converts an array of string values into a single CSV line. All <code>null</code> values are - * converted to the string <code>"null"</code>, all strings equal to <code>"null"</code> will - * additionally get quotes around. - * - * @param values the value array - * @return the CSV string, will be an empty string if the length of the value array is 0 - */ - public static String printLine(String[] values, CSVStrategy strategy) { - // set up a CSVUtils - StringWriter stringWriter = new StringWriter(); - CSVPrinter csvPrinter = new CSVPrinter(stringWriter, strategy); - - // check for null values an "null" as strings and convert them - // into the strings "null" and "\"null\"" - for (int i = 0; i < values.length; i++) { - if (values[i] == null) { - values[i] = "null"; - } else if (values[i].equals("null")) { - values[i] = "\"null\""; - } - } - - // convert to CSV - try { - csvPrinter.println(values); - } catch (IOException e) { - // should not happen with StringWriter - } - // as the resulting string has \r\n at the end, we will trim that away - return stringWriter.toString().trim(); - } - // ====================================================== // static parsers // ====================================================== @@ -105,7 +71,7 @@ public class CSVUtils { throw new IllegalArgumentException("Null argument not allowed."); } // uh,jh: make sure that parseLine("").length == 0 - if (s.length() == 0) { + if (s.isEmpty()) { return EMPTY_STRING_ARRAY; } return (new CSVParser(new StringReader(s))).getLine(); diff --git a/solr/core/src/java/org/apache/solr/internal/csv/ExtendedBufferedReader.java b/solr/core/src/java/org/apache/solr/internal/csv/ExtendedBufferedReader.java index fb7621490ea..fa9266256b9 100644 --- a/solr/core/src/java/org/apache/solr/internal/csv/ExtendedBufferedReader.java +++ b/solr/core/src/java/org/apache/solr/internal/csv/ExtendedBufferedReader.java @@ -23,11 +23,11 @@ import java.io.Reader; /** * ExtendedBufferedReader * - * <p>A special reader decorater which supports more sophisticated access to the underlying reader + * <p>A special reader decorator which supports more sophisticated access to the underlying reader * object. * * <p>In particular the reader supports a look-ahead option, which allows you to see the next char - * returned by next(). Furthermore the skip-method supports skipping until (but excluding) a given + * returned by next(). Furthermore, the skip-method supports skipping until (but excluding) a given * char. Similar functionality is supported by the reader as well. */ class ExtendedBufferedReader extends BufferedReader { @@ -98,7 +98,7 @@ class ExtendedBufferedReader extends BufferedReader { } /** - * Non-blocking reading of len chars into buffer buf starting at bufferposition off. + * Non-blocking reading of len chars into buffer buf starting at buffer position off. * * <p>performs an iterative read on the underlying stream as long as the following conditions * hold: - less than len chars have been read - end of stream has not been reached - next read is @@ -215,7 +215,7 @@ class ExtendedBufferedReader extends BufferedReader { * * <p>ATTENTION: invalidates the line-counter !!!!! * - * @return nof skiped chars + * @return nof skipped chars */ @Override public long skip(long n) throws IllegalArgumentException, IOException { @@ -235,14 +235,14 @@ class ExtendedBufferedReader extends BufferedReader { } // skip and reread the lookahead-char - long skiped = 0; + long skipped = 0; if (n > 1) { - skiped = super.skip(n - 1); + skipped = super.skip(n - 1); } lookaheadChar = super.read(); - // fixme uh: we should check the skiped sequence for line-terminations... + // fixme uh: we should check the skipped sequence for line-terminations... lineCounter = Integer.MIN_VALUE; - return skiped + 1; + return skipped + 1; } /** @@ -269,7 +269,7 @@ class ExtendedBufferedReader extends BufferedReader { /** * Returns the next char in the stream without consuming it. * - * <p>Remember the next char read by read(..) will always be identical to lookAhead(). + * <p>Remember the next char read by read() will always be identical to lookAhead(). * * @return the next char (without consuming it) or END_OF_STREAM */ @@ -295,7 +295,7 @@ class ExtendedBufferedReader extends BufferedReader { @Override public boolean markSupported() { - /* note uh: marking is not supported, cause we cannot + /* note uh: marking is not supported, because we cannot * see into the future... */ return false; diff --git a/solr/core/src/java/org/apache/solr/logging/LogWatcher.java b/solr/core/src/java/org/apache/solr/logging/LogWatcher.java index 30f4f6e2755..c4cd3d763d1 100644 --- a/solr/core/src/java/org/apache/solr/logging/LogWatcher.java +++ b/solr/core/src/java/org/apache/solr/logging/LogWatcher.java @@ -68,9 +68,9 @@ public abstract class LogWatcher<E> { public abstract String getThreshold(); - public void add(E event, long timstamp) { + public void add(E event, long timestamp) { history.add(unmodifiable(toSolrDocument(event))); - last = timstamp; + last = timestamp; } /** diff --git a/solr/core/src/java/org/apache/solr/logging/jul/JulWatcher.java b/solr/core/src/java/org/apache/solr/logging/jul/JulWatcher.java index 271e1358fd1..9cb3acc0b0c 100644 --- a/solr/core/src/java/org/apache/solr/logging/jul/JulWatcher.java +++ b/solr/core/src/java/org/apache/solr/logging/jul/JulWatcher.java @@ -150,7 +150,7 @@ public class JulWatcher extends LogWatcher<LogRecord> { doc.setField("time", new Date(event.getMillis())); doc.setField("level", event.getLevel().toString()); doc.setField("logger", event.getLoggerName()); - doc.setField("message", event.getMessage().toString()); + doc.setField("message", event.getMessage()); Throwable t = event.getThrown(); if (t != null) { StringWriter trace = new StringWriter(); diff --git a/solr/core/src/java/org/apache/solr/logging/log4j2/Log4j2Watcher.java b/solr/core/src/java/org/apache/solr/logging/log4j2/Log4j2Watcher.java index 9e266baa5ad..f8c2391085f 100644 --- a/solr/core/src/java/org/apache/solr/logging/log4j2/Log4j2Watcher.java +++ b/solr/core/src/java/org/apache/solr/logging/log4j2/Log4j2Watcher.java @@ -183,7 +183,7 @@ public class Log4j2Watcher extends LogWatcher<LogEvent> { LoggerConfig rootConfig = ctx.getConfiguration().getRootLogger(); Map<String, LoggerInfo> map = new HashMap<>(ctx.getLoggers().size()); - // First add the ROOT loger with the ROOT level + // First add the ROOT logger with the ROOT level map.put( LoggerInfo.ROOT_NAME, new Log4j2Info(
