use of java.io.PrintStream in project smile by haifengl.
the class ToyData method main.
public static void main(String[] argv) {
ToyData toy = new ToyData();
int n = 100;
double[][] s = toy.sample(n);
try (PrintStream p = new PrintStream(new FileOutputStream("toy-train.txt"))) {
for (int i = 0; i < s.length; i++) {
int label = i / n;
p.format("%d\t% .4f\t% .4f\n", label, s[i][0], s[i][1]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
n = 10000;
s = toy.sample(n);
try (PrintStream p = new PrintStream(new FileOutputStream("toy-test.txt"))) {
for (int i = 0; i < s.length; i++) {
int label = i / n;
p.format("%d\t% .4f\t% .4f\n", label, s[i][0], s[i][1]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
use of java.io.PrintStream in project h2o-3 by h2oai.
the class TeeOutputStream method startTestSuite.
public void startTestSuite(String testSuiteName) throws Exception {
testSuiteStartTime = System.currentTimeMillis();
document = docBuilder.newDocument();
// test suite
testSuiteElement = document.createElement("testsuite");
document.appendChild(testSuiteElement);
testSuiteElement.setAttribute("name", StringEscapeUtils.escapeXml(testSuiteName));
testSuiteElement.setAttribute("timestamp", StringEscapeUtils.escapeXml(dateFormat.format(new Date(testSuiteStartTime))));
testSuiteElement.setAttribute("hostname", StringEscapeUtils.escapeXml(InetAddress.getLocalHost().getHostName()));
testSuiteElement.setAttribute("ncpu", StringEscapeUtils.escapeXml(Integer.toString(Runtime.getRuntime().availableProcessors())));
// system properties
Element propertiesElement = document.createElement("properties");
testSuiteElement.appendChild(propertiesElement);
for (String name : System.getProperties().stringPropertyNames()) {
Element propertyElement = document.createElement("property");
propertyElement.setAttribute("name", StringEscapeUtils.escapeXml(name));
propertyElement.setAttribute("value", StringEscapeUtils.escapeXml(System.getProperty(name)));
propertiesElement.appendChild(propertyElement);
}
// reset counters
testCount = 0;
successCount = 0;
failureCount = 0;
// redirect outputs
stdOut = System.out;
out = new ByteArrayOutputStream();
System.setOut(new PrintStream(new TeeOutputStream(out, stdOut), true));
stdErr = System.err;
err = new ByteArrayOutputStream();
System.setErr(new PrintStream(new TeeOutputStream(err, stdErr), true));
}
use of java.io.PrintStream in project jslint4java by happygiraffe.
the class StdioResource method captureStderr.
private void captureStderr() {
origErr = System.err;
stderrStream = new ByteArrayOutputStream();
System.setErr(new PrintStream(stderrStream));
}
use of java.io.PrintStream in project jslint4java by happygiraffe.
the class StdioResource method captureStdout.
private void captureStdout() {
origOut = System.out;
stdoutStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(stdoutStream));
}
use of java.io.PrintStream in project Gaffer by gchq.
the class IngestUtils method createSplitsFile.
/**
* Get the existing splits from a table in Accumulo and write a splits file.
* The number of splits is returned.
*
* @param conn - An existing connection to an Accumulo instance
* @param table - The table name
* @param fs - The FileSystem in which to create the splits file
* @param splitsFile - A Path for the output splits file
* @param maxSplits - The maximum number of splits
* @return The number of splits in the table
* @throws IOException for any IO issues reading from the file system. Other accumulo exceptions are caught and wrapped in an IOException.
*/
public static int createSplitsFile(final Connector conn, final String table, final FileSystem fs, final Path splitsFile, final int maxSplits) throws IOException {
LOGGER.info("Creating splits file in location {} from table {} with maximum splits {}", splitsFile, table, maxSplits);
// Get the splits from the table
Collection<Text> splits;
try {
splits = conn.tableOperations().listSplits(table, maxSplits);
} catch (TableNotFoundException | AccumuloSecurityException | AccumuloException e) {
throw new IOException(e.getMessage(), e);
}
// This should have returned at most maxSplits splits, but this is not implemented properly in MockInstance.
if (splits.size() > maxSplits) {
if (conn instanceof MockConnector) {
LOGGER.info("Manually reducing the number of splits to {} due to MockInstance not implementing" + " listSplits(table, maxSplits) properly", maxSplits);
} else {
LOGGER.info("Manually reducing the number of splits to {} (number of splits was {})", maxSplits, splits.size());
}
final Collection<Text> filteredSplits = new TreeSet<>();
final int outputEveryNth = splits.size() / maxSplits;
LOGGER.info("Outputting every {}-th split from {} total", outputEveryNth, splits.size());
int i = 0;
for (final Text text : splits) {
if (i % outputEveryNth == 0) {
filteredSplits.add(text);
}
i++;
if (filteredSplits.size() >= maxSplits) {
break;
}
}
splits = filteredSplits;
}
LOGGER.info("Found {} splits from table {}", splits.size(), table);
try (final PrintStream out = new PrintStream(new BufferedOutputStream(fs.create(splitsFile, true)), false, CommonConstants.UTF_8)) {
// Write the splits to file
if (splits.isEmpty()) {
out.close();
return 0;
}
for (final Text split : splits) {
out.println(new String(Base64.encodeBase64(split.getBytes()), CommonConstants.UTF_8));
}
}
return splits.size();
}
Aggregations