Skip to content
Merged
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
53 changes: 8 additions & 45 deletions src/org/labkey/serverapi/reader/TabLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.CharSequenceReader;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.test.util.TestLogger;
import org.jspecify.annotations.NonNull;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -104,24 +103,15 @@ public static class CsvFactoryNoConversions extends CsvFactory
@Override
public DataLoader createLoader(File file, boolean hasColumnHeaders) throws IOException
{

DataLoader loader = super.createLoader(file, hasColumnHeaders);
return loader;
return super.createLoader(file, hasColumnHeaders);
}

@NotNull
@Override
// A DataLoader created with this constructor does NOT close the reader
public DataLoader createLoader(InputStream is, boolean hasColumnHeaders) throws IOException
{
DataLoader loader = super.createLoader(is, hasColumnHeaders);
return loader;
}

@Override
public @NotNull FileType getFileType()
{
return CSV_FILE_TYPE;
return super.createLoader(is, hasColumnHeaders);
}
}

Expand All @@ -135,13 +125,12 @@ public DataLoader createLoader(InputStream is, boolean hasColumnHeaders) throws
private int _commentLines = 0;
private final Map<String, String> _comments = new HashMap<>();
private char _chDelimiter = '\t';
private String _strDelimiter = new String(new char[]{_chDelimiter});
private String _strDelimiter = String.valueOf(_chDelimiter);
private String _lineDelimiter = null;

private String _strQuote = null;
private String _strQuoteQuote = null;
private boolean _parseQuotes = true;
private final boolean _unescapeBackslashes = false;
private Filter<Map<String, Object>> _mapFilter;

// Infer whether there are headers
Expand Down Expand Up @@ -267,26 +256,6 @@ protected String parseValue(String value)
value = StringUtils.trimToEmpty(value);
if ("\\N".equals(value))
return _preserveEmptyString ? null : "";
if (_unescapeBackslashes)
{
try
{
return StringEscapeUtils.unescapeJava(value);
}
catch (IllegalArgumentException e)
{
// Issue 16691: OctalUnescaper or UnicodeUnescaper translators will throw NumberFormatException for illegal sequences such as '\' followed by octal '9' or unicode 'zzzz'.
// StringEscapeUtils can also throw IllegalArgumentException
String msg = "Error reading data. Can't unescape value '" + value + "'. ";
if (e instanceof NumberFormatException)
msg += "Number format error ";
msg += e.getMessage();
if (isThrowOnErrors())
throw new IllegalArgumentException(msg, e);
else
TestLogger.warn(msg, e);
}
}
return value;
}

Expand All @@ -306,7 +275,7 @@ private CharSequence readLine(BufferedReader r, boolean skipComments, boolean sk
sb.append("\n");
if (line.endsWith(_lineDelimiter))
{
sb.append(line.substring(0, line.length() - _lineDelimiter.length()));
sb.append(line, 0, line.length() - _lineDelimiter.length());
return sb;
}
sb.append(line);
Expand Down Expand Up @@ -377,7 +346,7 @@ else if (ch == chQuote)
{
if (_strQuote == null)
{
_strQuote = new String(new char[]{chQuote});
_strQuote = String.valueOf(chQuote);
_strQuoteQuote = new String(new char[]{chQuote, chQuote});
_replaceDoubleQuotes = Pattern.compile("\\" + chQuote + "\\" + chQuote);
}
Expand Down Expand Up @@ -465,14 +434,8 @@ else if (ch == chQuote)
return listParse.toArray(new String[0]);
}

@Deprecated // Just use a CloseableFilteredIterator. TODO: Remove
public void setMapFilter(Filter<Map<String, Object>> mapFilter)
{
_mapFilter = mapFilter;
}

@Override
public CloseableIterator<Map<String, Object>> iterator()
public @NonNull CloseableIterator<Map<String, Object>> iterator()
{
TabLoaderIterator iter;
try
Expand Down Expand Up @@ -501,7 +464,7 @@ public void parseAsCSV()
public void setDelimiterCharacter(char delimiter)
{
_chDelimiter = delimiter;
_strDelimiter = new String(new char[]{_chDelimiter});
_strDelimiter = String.valueOf(_chDelimiter);
}

public void setDelimiters(@NotNull String field, @Nullable String line)
Expand Down