本文整理汇总了Java中com.csvreader.CsvWriter.flush方法的典型用法代码示例。如果您正苦于以下问题:Java CsvWriter.flush方法的具体用法?Java CsvWriter.flush怎么用?Java CsvWriter.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.csvreader.CsvWriter
的用法示例。
在下文中一共展示了CsvWriter.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test120
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
@Test
public void test120() throws Exception {
byte[] buffer;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
CsvWriter writer = new CsvWriter(stream, ',', Charset
.forName("ISO-8859-1"));
writer.write("1,2");
writer.endRecord();
buffer = stream.toByteArray();
String data = Charset.forName("ISO-8859-1").decode(
ByteBuffer.wrap(buffer)).toString();
Assert.assertEquals("", data);
writer.flush(); // testing that flush flushed to stream
buffer = stream.toByteArray();
stream.close();
data = Charset.forName("ISO-8859-1").decode(ByteBuffer.wrap(buffer))
.toString();
Assert.assertEquals("\"1,2\"\r\n", data);
writer.close();
}
示例2: writeObservationList
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
protected long writeObservationList(List<ObservationState> states) throws IOException {
DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
syncOutput.setHeader("Content-Type", "text/tab-separated-values");
OutputStream os = syncOutput.getOutputStream();
ByteCountOutputStream bc = new ByteCountOutputStream(os);
OutputStreamWriter out = new OutputStreamWriter(bc, "US-ASCII");
CsvWriter writer = new CsvWriter(out, '\t');
for (ObservationState state : states) {
writer.write(state.getURI().getCollection());
writer.write(state.getURI().getObservationID());
if (state.maxLastModified != null) {
writer.write(df.format(state.maxLastModified));
} else {
writer.write("");
}
if (state.accMetaChecksum != null) {
writer.write(state.accMetaChecksum.toASCIIString());
} else {
writer.write("");
}
writer.endRecord();
}
writer.flush();
return bc.getByteCount();
}
示例3: writeDeleted
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
private long writeDeleted(List<DeletedObservation> dels) throws IOException {
DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
syncOutput.setHeader("Content-Type", "text/tab-separated-values");
OutputStream os = syncOutput.getOutputStream();
ByteCountOutputStream bc = new ByteCountOutputStream(os);
OutputStreamWriter out = new OutputStreamWriter(bc, "US-ASCII");
CsvWriter writer = new CsvWriter(out, '\t');
for (DeletedObservation ddo : dels) {
writer.write(ddo.getID().toString());
writer.write(ddo.getURI().getCollection());
writer.write(ddo.getURI().getObservationID());
if (ddo.getLastModified() != null) {
writer.write(df.format(ddo.getLastModified()));
} else {
writer.write("");
}
writer.endRecord();
}
writer.flush();
return bc.getByteCount();
}
示例4: writeObservationList
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
@Override
protected long writeObservationList(List<ObservationState> states) throws IOException {
DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
syncOutput.setHeader("Content-Type", "text/csv");
OutputStream os = syncOutput.getOutputStream();
ByteCountOutputStream bc = new ByteCountOutputStream(os);
CsvWriter writer = new CsvWriter(bc, ',', Charset.defaultCharset());
for (ObservationState state : states) {
writer.write(state.getURI().getObservationID());
writer.write(df.format(state.maxLastModified));
writer.endRecord();
}
writer.flush();
return bc.getByteCount();
}
示例5: doGetCollectionList
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
protected void doGetCollectionList() throws Exception {
log.debug("START: (collection list)");
CaomRepoConfig curConfig = getConfig();
Iterator<String> collectionListIterator = curConfig.collectionIterator();
syncOutput.setHeader("Content-Type", "text/tab-separated-values");
OutputStream os = syncOutput.getOutputStream();
ByteCountOutputStream bc = new ByteCountOutputStream(os);
OutputStreamWriter out = new OutputStreamWriter(bc, "US-ASCII");
CsvWriter writer = new CsvWriter(out, '\t');
while (collectionListIterator.hasNext()) {
String collectionName = collectionListIterator.next();
// Write out a single column as one entry per row
if (!collectionName.isEmpty()) {
writer.write(collectionName);
writer.endRecord();
}
}
writer.flush();
logInfo.setBytes(bc.getByteCount());
}
示例6: formatData
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
/**
* Called to output the data. This class uses a third party library to output
* the CSV data. The library escapes the data as needed.
*
* @param out the PrintStream to output data to.
* @param resultSet the ResultSet for the row.
* @param metaData the ResultSetMetaData for the row.
*
*
*/
public void formatData( PrintStream out, ResultSet resultSet, ResultSetMetaData metaData ) throws Exception {
CsvWriter csvWriter = new CsvWriter( out, delimiter, Charset.forName( "us-ascii" ) );
while( resultSet.next() ) {
int numColumns = metaData.getColumnCount();
for (int i = 1; i <= numColumns; i++) {
String result = resultSet.getString(i);
if( !resultSet.wasNull() )
csvWriter.write( result );
else
csvWriter.write( "" );
}
csvWriter.endRecord();
}
csvWriter.flush();
}
示例7: joinAsCsv
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
/**
* Joins the given values as a comma-separated string. Each value will be encoded in this string by escaping any
* commas in the value with a backslash.
*
* @param values the values to join (null is acceptable).
* @return the CSV string consisting of the values. If the values were null, an empty String.
*/
public static String joinAsCsv(String[] values) {
if (values == null) {
return StringUtils.EMPTY;
}
try {
final StringWriter sw = new StringWriter();
final CsvWriter csvWriter = new CsvWriter(sw, ',');
csvWriter.setEscapeMode(CsvWriter.ESCAPE_MODE_BACKSLASH);
csvWriter.setUseTextQualifier(false);
csvWriter.writeRecord(values);
csvWriter.flush();
csvWriter.close();
return sw.toString();
} catch (final IOException e) {
throw new IllegalStateException("Could not encode as CSV record: " + e, e);
}
}
示例8: writeToFile
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
protected void writeToFile(List<ExportEntry> csvEntries) throws IOException {
CsvWriter cwriter = new CsvWriter(fileOutpuStream, VaultCsvEntry.CSV_DELIMITER,
Charset.forName("UTF-8"));
cwriter.writeRecord(((CsvEntry) csvEntries.get(0)).getCsvHeaderRecord());
for (ExportEntry item : csvEntries) {
cwriter.writeRecord(((CsvEntry) item).toCsvRecord());
}
cwriter.flush();
cwriter.close();
}
示例9: writeToFile
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
@Override
protected void writeToFile(List<ExportEntry> csvEntries) throws IOException {
// Setup compression stuff
ZipOutputStream zos = new ZipOutputStream(fileOutpuStream);
zos.setMethod(ZipOutputStream.DEFLATED);
zos.setLevel(9);
// Setup signature stuff
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-512");
} catch (NoSuchAlgorithmException ex) {
LOG.log(Level.SEVERE, "Missing hash algorithm for signature. No file exported!", ex);
throw new IOException("Missing hash algorithm for signature.");
}
DigestOutputStream dos = new DigestOutputStream(zos, md);
// write data
zos.putNextEntry(new ZipEntry(DATA_ZIP_ENTRY));
CsvWriter cwriter = new CsvWriter(dos, VaultCsvEntry.CSV_DELIMITER,
Charset.forName("UTF-8"));
cwriter.writeRecord(((CsvEntry) csvEntries.get(0)).getCsvHeaderRecord());
for (ExportEntry item : csvEntries) {
cwriter.writeRecord(((CsvEntry) item).toCsvRecord());
}
cwriter.flush();
// add signature file
zos.putNextEntry(new ZipEntry(SIGNATURE_ZIP_ENTRY));
String sigString = (new HexBinaryAdapter()).marshal(md.digest());
zos.write(sigString.getBytes(), 0, sigString.getBytes().length);
// close everything
cwriter.close();
dos.close();
zos.close();
fileOutpuStream.close();
}
示例10: writeToFile
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
protected void writeToFile(final List<ExportEntry> csvEntries) throws IOException {
FileOutputStream fileOutputStream = getFileOutputStream();
CsvWriter cwriter = new CsvWriter(fileOutputStream, VaultCsvEntry.CSV_DELIMITER, Charset.forName("UTF-8"));
cwriter.writeRecord(((CsvEntry) csvEntries.get(0)).getCsvHeaderRecord());
for (ExportEntry item : csvEntries) {
cwriter.writeRecord(((CsvEntry) item).toCsvRecord());
}
cwriter.flush();
cwriter.close();
}
示例11: writeCsvViolations
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
private void writeCsvViolations(String basecase, List<LimitViolation> networkViolations, CsvWriter cvsWriter)
throws IOException {
for (LimitViolation violation : networkViolations) {
String[] values = new String[] {basecase, violation.getSubjectId(), violation.getLimitType().name(),
Float.toString(violation.getValue()), Float.toString(violation.getLimit()) };
cvsWriter.writeRecord(values);
}
cvsWriter.flush();
}
示例12: writeToFile
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
/**
* Writes the data to a CSV file and generates a signature hash.
* Then it puts both of this into a ZIP archive file.
*
* @param csvEntries The {@link ExportEntry} to be exported.
* @throws IOException Thrown if the SHA-512 hash algorithm is missing.
*/
@Override
protected void writeToFile(final List<ExportEntry> csvEntries) throws IOException {
// Setup compression stuff
FileOutputStream fileOutputStream = getFileOutputStream();
final int zipCompressionLevel = 9;
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
zipOutputStream.setMethod(ZipOutputStream.DEFLATED);
zipOutputStream.setLevel(zipCompressionLevel);
// Setup signature
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-512");
} catch (NoSuchAlgorithmException exception) {
LOG.log(Level.SEVERE, "Missing hash algorithm for signature. No file exported!", exception);
throw new IOException("Missing hash algorithm for signature.");
}
DigestOutputStream digestOutputStream = new DigestOutputStream(zipOutputStream, digest);
// write data
zipOutputStream.putNextEntry(new ZipEntry(DATA_ZIP_ENTRY));
CsvWriter cwriter = new CsvWriter(digestOutputStream, VaultCsvEntry.CSV_DELIMITER,
Charset.forName("UTF-8"));
cwriter.writeRecord(((CsvEntry) csvEntries.get(0)).getCsvHeaderRecord());
for (ExportEntry item : csvEntries) {
cwriter.writeRecord(((CsvEntry) item).toCsvRecord());
}
cwriter.flush();
// add signature file
zipOutputStream.putNextEntry(new ZipEntry(SIGNATURE_ZIP_ENTRY));
String sigString = (new HexBinaryAdapter()).marshal(digest.digest());
zipOutputStream.write(sigString.getBytes("UTF-8"), 0, sigString.getBytes("UTF-8").length);
// Closing the streams
cwriter.close();
digestOutputStream.close();
zipOutputStream.close();
fileOutputStream.close();
}
示例13: run
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
@Override
public void run(CommandLine line, ToolRunningContext context) throws Exception {
OnlineConfig config = OnlineConfig.load();
OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create();
String workflowId = line.getOptionValue("workflow");
OnlineWorkflowWcaResults wfWcaResults = onlinedb.getWcaResults(workflowId);
if (wfWcaResults != null) {
if (!wfWcaResults.getContingencies().isEmpty()) {
Table table = new Table(7, BorderStyle.CLASSIC_WIDE);
StringWriter content = new StringWriter();
CsvWriter cvsWriter = new CsvWriter(content, ',');
String[] headers = new String[7];
int i = 0;
table.addCell("Contingency", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "Contingency";
table.addCell("Cluster 1", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "Cluster 1";
table.addCell("Cluster 2", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "Cluster 2";
table.addCell("Cluster 3", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "Cluster 3";
table.addCell("Cluster 4", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "Cluster 4";
table.addCell("Undefined", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "Undefined";
table.addCell("Cause", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "Cause";
cvsWriter.writeRecord(headers);
for (String contingencyId : wfWcaResults.getContingencies()) {
String[] values = new String[7];
i = 0;
table.addCell(contingencyId);
values[i++] = contingencyId;
int[] clusterIndexes = new int[]{1, 2, 3, 4, -1};
for (int k = 0; k < clusterIndexes.length; k++) {
if (clusterIndexes[k] == wfWcaResults.getClusterIndex(contingencyId)) {
table.addCell("X", new CellStyle(CellStyle.HorizontalAlign.center));
values[i++] = "X";
} else {
table.addCell("-", new CellStyle(CellStyle.HorizontalAlign.center));
values[i++] = "-";
}
}
table.addCell(Objects.toString(wfWcaResults.getCauses(contingencyId), " "), new CellStyle(CellStyle.HorizontalAlign.center));
values[i++] = Objects.toString(wfWcaResults.getCauses(contingencyId), " ");
cvsWriter.writeRecord(values);
}
cvsWriter.flush();
if (line.hasOption("csv")) {
context.getOutputStream().println(content.toString());
} else {
context.getOutputStream().println(table.render());
}
cvsWriter.close();
} else {
context.getOutputStream().println("\nNo results of security rules applications for this workflow");
}
} else {
context.getOutputStream().println("No results for this workflow");
}
onlinedb.close();
}
示例14: run
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
@Override
public void run(CommandLine line, ToolRunningContext context) throws Exception {
OnlineConfig config = OnlineConfig.load();
OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create();
String workflowId = line.getOptionValue("workflow");
OnlineWorkflowResults wfResults = onlinedb.getResults(workflowId);
if (wfResults != null) {
if (!wfResults.getContingenciesWithActions().isEmpty()) {
Table table = new Table(5, BorderStyle.CLASSIC_WIDE);
StringWriter content = new StringWriter();
CsvWriter cvsWriter = new CsvWriter(content, ',');
String[] headers = new String[5];
int i = 0;
table.addCell("Contingency", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "Contingency";
table.addCell("State", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "State";
table.addCell("Actions Found", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "Actions Found";
table.addCell("Status", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "Status";
table.addCell("Actions", new CellStyle(CellStyle.HorizontalAlign.center));
headers[i++] = "Actions";
cvsWriter.writeRecord(headers);
for (String contingencyId : wfResults.getContingenciesWithActions()) {
for (Integer stateId : wfResults.getUnsafeStatesWithActions(contingencyId).keySet()) {
String[] values = new String[5];
i = 0;
table.addCell(contingencyId);
values[i++] = contingencyId;
table.addCell(stateId.toString(), new CellStyle(CellStyle.HorizontalAlign.right));
values[i++] = stateId.toString();
table.addCell(Boolean.toString(wfResults.getUnsafeStatesWithActions(contingencyId).get(stateId)), new CellStyle(CellStyle.HorizontalAlign.right));
values[i++] = Boolean.toString(wfResults.getUnsafeStatesWithActions(contingencyId).get(stateId));
table.addCell(wfResults.getStateStatus(contingencyId, stateId).name());
values[i++] = wfResults.getStateStatus(contingencyId, stateId).name();
String json = "-";
if (wfResults.getActionsIds(contingencyId, stateId) != null) {
// json = Utils.actionsToJson(wfResults, contingencyId, stateId);
json = Utils.actionsToJsonExtended(wfResults, contingencyId, stateId);
}
table.addCell(json);
values[i++] = json;
cvsWriter.writeRecord(values);
}
}
cvsWriter.flush();
if (line.hasOption("csv")) {
context.getOutputStream().println(content.toString());
} else {
context.getOutputStream().println(table.render());
}
cvsWriter.close();
} else {
context.getOutputStream().println("\nNo contingencies requiring corrective actions");
}
} else {
context.getOutputStream().println("No results for this workflow");
}
onlinedb.close();
}
示例15: render
import com.csvreader.CsvWriter; //导入方法依赖的package包/类
public void render(Result result) throws IOException {
CsvWriter csvWriter = new CsvWriter(this.outputStream, this.delimiter, this.charset);
// basics
csvWriter.write("Algorithm");
csvWriter.write("Problem");
// times
csvWriter.write("CPU Time [ms]");
csvWriter.write("System Time [ms]");
csvWriter.write("User Time [ms]");
csvWriter.write("Clock Time [ms]");
// optimize stats
csvWriter.write("Optimize counter");
csvWriter.write("Optimize/sec (CPU) [1/s]");
csvWriter.write("Optimize/sec (Clock) [1/s]");
// solution
csvWriter.write("Exception");
csvWriter.write("Best solution");
csvWriter.write("Best solution (human readable)");
csvWriter.write("Depth");
csvWriter.write("Fitness");
csvWriter.write("Operations");
csvWriter.endRecord();
for (ResultEntry resultEntry : result.getResultEntries()) {
PreciseTimestamp start = resultEntry.getStartTimestamp();
PreciseTimestamp stop = resultEntry.getStopTimestamp();
// basics
csvWriter.write(resultEntry.getAlgorithm().toString());
csvWriter.write(resultEntry.getProblem().toString());
// times
csvWriter.write(Long.toString(start.getCpuTimeSpent(stop)));
csvWriter.write(Long.toString(start.getSystemTimeSpent(stop)));
csvWriter.write(Long.toString(start.getUserTimeSpent(stop)));
csvWriter.write(Long.toString(start.getClockTimeSpent(stop)));
// optimize stats
csvWriter.write(Long.toString(resultEntry.getOptimizeCounter()));
csvWriter.write(Long.toString(resultEntry.getOptimizeCounter() * 1000L / start.getCpuTimeSpent(stop)));
csvWriter.write(Long.toString(resultEntry.getOptimizeCounter() * 1000L / start.getClockTimeSpent(stop)));
csvWriter.write(resultEntry.getException() == null ? "none" : resultEntry.getException().getClass().toString());
// solution
if (resultEntry.getBestConfiguration() == null) {
csvWriter.write("none");
csvWriter.write("-");
csvWriter.write("-");
csvWriter.write("-");
} else {
StringBuffer stringBufferHumanReadable = new StringBuffer("[");
StringBuffer stringBuffer = new StringBuffer("[");
ConfigurationMap configurationMap = resultEntry.getProblem().getConfigurationMap();
for (int i = 0; i < resultEntry.getBestConfiguration().getDimension(); ++i) {
stringBuffer.append(i == 0 ? "" : ", ").append(configurationMap.map(resultEntry.getBestConfiguration().valueAt(i), i));
stringBufferHumanReadable.append(i == 0 ? "" : ", ").append(resultEntry.getBestConfiguration().valueAt(i));
}
stringBuffer.append("]");
stringBufferHumanReadable.append("]");
csvWriter.write(stringBuffer.toString());
csvWriter.write(stringBufferHumanReadable.toString());
csvWriter.write(Long.toString(resultEntry.getBestConfiguration().getOperationHistory().getCounter()));
csvWriter.write(Double.toString(resultEntry.getBestFitness()));
for (OperationHistory operationHistory : resultEntry.getBestConfiguration().getOperationHistory().getChronologicalList()) {
csvWriter.write(operationHistory.getOperation().toString());
}
}
csvWriter.endRecord();
}
csvWriter.flush();
}