private void convertChunks() throws IOException, InterruptedException { int lastNumCharacters = 1024 * 64; while (!Thread.interrupted() && m_saveFile.hasMoreChunks()) { if (m_availableBytes.get() > m_maxAvailableBytes) { Thread.sleep(5); continue; } BBContainer c = m_saveFile.getNextChunk(); if (c == null) { return; } try { final VoltTable vt = PrivateVoltTableFactory.createVoltTableFromBuffer(c.b(), true); Pair<Integer, byte[]> p = VoltTableUtil.toCSV(vt, m_delimiter, null, lastNumCharacters); lastNumCharacters = p.getFirst(); byte csvBytes[] = p.getSecond(); // should not insert empty byte[] if not last ConverterThread if (csvBytes.length > 0) { m_availableBytes.addAndGet(csvBytes.length); m_available.offer(csvBytes); } } finally { c.discard(); } } }
@Override public void printTable(PrintStream stream, VoltTable t, boolean includeColumnNames) throws IOException { final int columnCount = t.getColumnCount(); List<VoltType> columnTypes = new ArrayList<VoltType>(columnCount); for (int i = 0; i < columnCount; i++) { columnTypes.add(t.getColumnType(i)); } CSVWriter csvWriter = new CSVWriter(new OutputStreamWriter(stream)); if (includeColumnNames) { String[] columnNames = new String[columnCount]; for (int i = 0; i < columnCount; i++) { columnNames[i] = t.getColumnName(i); } csvWriter.writeNext(columnNames); } VoltTableUtil.toCSVWriter(csvWriter, t, columnTypes); }