(BufferedReader reader, boolean tsv,
File outputFile)
| 4838 | |
| 4839 | // converts a TSV or CSV file to binary.. do not use |
| 4840 | protected void convertBasic(BufferedReader reader, boolean tsv, |
| 4841 | File outputFile) throws IOException { |
| 4842 | FileOutputStream fos = new FileOutputStream(outputFile); |
| 4843 | BufferedOutputStream bos = new BufferedOutputStream(fos, 16384); |
| 4844 | DataOutputStream output = new DataOutputStream(bos); |
| 4845 | output.writeInt(0); // come back for row count |
| 4846 | output.writeInt(getColumnCount()); |
| 4847 | if (columnTitles != null) { |
| 4848 | output.writeBoolean(true); |
| 4849 | for (String title : columnTitles) { |
| 4850 | output.writeUTF(title); |
| 4851 | } |
| 4852 | } else { |
| 4853 | output.writeBoolean(false); |
| 4854 | } |
| 4855 | for (int type : columnTypes) { |
| 4856 | output.writeInt(type); |
| 4857 | } |
| 4858 | |
| 4859 | String line = null; |
| 4860 | //setRowCount(1); |
| 4861 | int prev = -1; |
| 4862 | int row = 0; |
| 4863 | while ((line = reader.readLine()) != null) { |
| 4864 | convertRow(output, tsv ? PApplet.split(line, '\t') : splitLineCSV(line, reader)); |
| 4865 | row++; |
| 4866 | |
| 4867 | if (row % 10000 == 0) { |
| 4868 | if (row < rowCount) { |
| 4869 | int pct = (100 * row) / rowCount; |
| 4870 | if (pct != prev) { |
| 4871 | System.out.println(pct + "%"); |
| 4872 | prev = pct; |
| 4873 | } |
| 4874 | } |
| 4875 | // try { |
| 4876 | // Thread.sleep(5); |
| 4877 | // } catch (InterruptedException e) { |
| 4878 | // e.printStackTrace(); |
| 4879 | // } |
| 4880 | } |
| 4881 | } |
| 4882 | // shorten or lengthen based on what's left |
| 4883 | // if (row != getRowCount()) { |
| 4884 | // setRowCount(row); |
| 4885 | // } |
| 4886 | |
| 4887 | // has to come afterwards, since these tables get built out during the conversion |
| 4888 | int col = 0; |
| 4889 | for (HashMapBlows hmb : columnCategories) { |
| 4890 | if (hmb == null) { |
| 4891 | output.writeInt(0); |
| 4892 | } else { |
| 4893 | hmb.write(output); |
| 4894 | hmb.writeln(PApplet.createWriter(new File(columnTitles[col] + ".categories"))); |
| 4895 | // output.writeInt(hmb.size()); |
| 4896 | // for (Map.Entry<String,Integer> e : hmb.entrySet()) { |
| 4897 | // output.writeUTF(e.getKey()); |
nothing calls this directly
no test coverage detected