mirror of
https://github.com/processing/processing4.git
synced 2026-02-07 07:39:18 +01:00
fix table loading quirk with extensions
This commit is contained in:
@@ -88,14 +88,12 @@ public class Table {
|
||||
|
||||
protected Object[] columns; // [column]
|
||||
|
||||
// typed data
|
||||
static final int STRING = 0;
|
||||
static final int INT = 1;
|
||||
static final int LONG = 2;
|
||||
static final int FLOAT = 3;
|
||||
static final int DOUBLE = 4;
|
||||
static final int CATEGORICAL = 5;
|
||||
// static final int TIME = 5;
|
||||
int[] columnTypes;
|
||||
|
||||
protected RowIterator rowIterator;
|
||||
@@ -105,26 +103,10 @@ public class Table {
|
||||
* Creates a new, empty table. Use addRow() to add additional rows.
|
||||
*/
|
||||
public Table() {
|
||||
// init(null);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
// public Table(PApplet sketch) {
|
||||
// init(sketch);
|
||||
// }
|
||||
|
||||
|
||||
// public Table(File file) {
|
||||
// this(PApplet.createReader(file));
|
||||
// }
|
||||
|
||||
|
||||
// public Table(PApplet parent, String filename) throws IOException {
|
||||
// this(parent, filename, null);
|
||||
// }
|
||||
|
||||
|
||||
public Table(File file) throws IOException {
|
||||
this(file, null);
|
||||
}
|
||||
@@ -155,7 +137,6 @@ public class Table {
|
||||
|
||||
|
||||
public Table(ResultSet rs) {
|
||||
// init(null);
|
||||
init();
|
||||
try {
|
||||
ResultSetMetaData rsmd = rs.getMetaData();
|
||||
@@ -251,29 +232,25 @@ public class Table {
|
||||
protected void parse(InputStream input, String options) throws IOException {
|
||||
init();
|
||||
|
||||
String[] opts = PApplet.fixOptions(options);
|
||||
// if (options != null) {
|
||||
// opts = options.split("\\s*,\\s*");
|
||||
//// PApplet.println("options:");
|
||||
//// PApplet.println(opts);
|
||||
|
||||
boolean awfulCSV = false;
|
||||
boolean header = false;
|
||||
String extension = null;
|
||||
for (String opt : opts) {
|
||||
if (opt.equals("tsv")) {
|
||||
extension = "tsv";
|
||||
} else if (opt.equals("csv")) {
|
||||
extension = "csv";
|
||||
} else if (opt.equals("newlines")) {
|
||||
awfulCSV = true;
|
||||
} else if (opt.equals("header")) {
|
||||
header = true;
|
||||
} else {
|
||||
throw new IllegalArgumentException("'" + opt + "' is not a valid option for loading a Table");
|
||||
if (options != null) {
|
||||
String[] opts = PApplet.splitTokens(options, " ,");
|
||||
for (String opt : opts) {
|
||||
if (opt.equals("tsv")) {
|
||||
extension = "tsv";
|
||||
} else if (opt.equals("csv")) {
|
||||
extension = "csv";
|
||||
} else if (opt.equals("newlines")) {
|
||||
awfulCSV = true;
|
||||
} else if (opt.equals("header")) {
|
||||
header = true;
|
||||
} else {
|
||||
throw new IllegalArgumentException("'" + opt + "' is not a valid option for loading a Table");
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
BufferedReader reader = PApplet.createReader(input);
|
||||
if (awfulCSV) {
|
||||
@@ -410,11 +387,6 @@ public class Table {
|
||||
}
|
||||
|
||||
|
||||
// protected String[] splitLine(String line) {
|
||||
// return commaSeparatedValues ? splitLineCSV(line) : PApplet.split(line, '\t');
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Parse a line of text as comma-separated values, returning each value as
|
||||
* one entry in an array of String objects. Remove quotes from entries that
|
||||
@@ -650,18 +622,20 @@ public class Table {
|
||||
|
||||
public void save(OutputStream output, String options) {
|
||||
PrintWriter writer = PApplet.createWriter(output);
|
||||
String[] opts = PApplet.fixOptions(options);
|
||||
for (String opt : opts) {
|
||||
if (opt.equals("csv")) {
|
||||
writeCSV(writer);
|
||||
} else if (opt.equals("tsv")) {
|
||||
writeTSV(writer);
|
||||
} else if (opt.equals("html")) {
|
||||
writeHTML(writer);
|
||||
} else {
|
||||
throw new IllegalArgumentException("'" + opt + "' not understood. " +
|
||||
"Only csv, tsv, and html are " +
|
||||
"accepted as save parameters");
|
||||
if (options != null) {
|
||||
String[] opts = PApplet.splitTokens(options, ", ");
|
||||
for (String opt : opts) {
|
||||
if (opt.equals("csv")) {
|
||||
writeCSV(writer);
|
||||
} else if (opt.equals("tsv")) {
|
||||
writeTSV(writer);
|
||||
} else if (opt.equals("html")) {
|
||||
writeHTML(writer);
|
||||
} else {
|
||||
throw new IllegalArgumentException("'" + opt + "' not understood. " +
|
||||
"Only csv, tsv, and html are " +
|
||||
"accepted as save parameters");
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.close();
|
||||
|
||||
Reference in New Issue
Block a user