org.apache.commons.io.output.TeeOutputStream Java Examples

The following examples show how to use org.apache.commons.io.output.TeeOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCppcheckCommand.java    From cppcheclipse with Apache License 2.0 6 votes vote down vote up
public AbstractCppcheckCommand(IConsole console, String[] defaultArguments,
		long timeout, String binaryPath) {

	this.binaryPath = binaryPath;
	this.console = console;
	this.defaultArguments = defaultArguments;
	
	executor = new DefaultExecutor();

	// all modes of operation returns 0 when no error occured,
	executor.setExitValue(0);

	watchdog = new ExecuteWatchdog(timeout);
	executor.setWatchdog(watchdog);

	out = new ByteArrayOutputStream();
	err = new ByteArrayOutputStream();

	processStdOut = new LineFilterOutputStream(new TeeOutputStream(out,
			console.getConsoleOutputStream(false)), DEFAULT_CHARSET);
	processStdErr = new LineFilterOutputStream(new TeeOutputStream(err,
			console.getConsoleOutputStream(true)), DEFAULT_CHARSET);
	
}
 
Example #2
Source File: HopGui.java    From hop with Apache License 2.0 6 votes vote down vote up
private static void setupConsoleLogging() {
  boolean doConsoleRedirect = !Boolean.getBoolean( "HopUi.Console.Redirect.Disabled" );
  if ( doConsoleRedirect ) {
    try {
      Path parent = Paths.get( Const.HOP_AUDIT_DIRECTORY );
      Files.createDirectories( parent );
      Files.deleteIfExists( Paths.get( parent.toString(), "hopui.log" ) );
      Path path = Files.createFile( Paths.get( parent.toString(), "hopui.log" ) );
      System.setProperty( "LOG_PATH", path.toString() );
      final FileOutputStream fos = new FileOutputStream( path.toFile() );
      System.setOut( new PrintStream( new TeeOutputStream( originalSystemOut, fos ) ) );
      System.setErr( new PrintStream( new TeeOutputStream( originalSystemErr, fos ) ) );
      HopLogStore.OriginalSystemOut = System.out;
      HopLogStore.OriginalSystemErr = System.err;
    } catch ( Throwable ignored ) {
      // ignored
    }
  }
}
 
Example #3
Source File: __platform-name__Collector.java    From ldbc_graphalytics with Apache License 2.0 6 votes vote down vote up
public static void startPlatformLogging(Path fileName) {
	defaultSysOut = System.out;
	deafultSysErr = System.err;
	try {
		File file = fileName.toFile();
		file.getParentFile().mkdirs();
		file.createNewFile();
		FileOutputStream fos = new FileOutputStream(file);
		TeeOutputStream bothStream = new TeeOutputStream(System.out, fos);
		PrintStream ps = new PrintStream(bothStream);
		System.setOut(ps);
		System.setErr(ps);
	} catch (Exception e) {
		e.printStackTrace();
		LOG.error("Failed to redirect to log file %s", fileName);
		throw new GraphalyticsExecutionException("Failed to log the benchmark run. Benchmark run aborted.");
	}
}
 
Example #4
Source File: ListExtensionsIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private List<String> listExtensions()
        throws MavenInvocationException, IOException {
    InvocationRequest request = new DefaultInvocationRequest();
    request.setBatchMode(true);
    request.setGoals(Collections.singletonList(
            getPluginGroupId() + ":" + getPluginArtifactId() + ":" + getPluginVersion() + ":list-extensions"));
    getEnv().forEach(request::addShellEnvironment);

    File outputLog = new File(testDir, "output.log");
    InvocationOutputHandler outputHandler = new PrintStreamHandler(
            new PrintStream(new TeeOutputStream(System.out, Files.newOutputStream(outputLog.toPath())), true, "UTF-8"),
            true);
    invoker.setOutputHandler(outputHandler);

    File invokerLog = new File(testDir, "invoker.log");
    PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(invokerLog), false, "UTF-8"),
            InvokerLogger.DEBUG);
    invoker.setLogger(logger);

    invoker.execute(request);
    return Files.readAllLines(outputLog.toPath());
}
 
Example #5
Source File: ResponseWrapper.java    From wisp with Apache License 2.0 6 votes vote down vote up
@Override
public ServletOutputStream getOutputStream() throws IOException {
    return new ServletOutputStream() {
        @Override
        public boolean isReady() {
            return false;
        }

        @Override
        public void setWriteListener(WriteListener writeListener) {

        }

        private TeeOutputStream tee = new TeeOutputStream(ResponseWrapper.super.getOutputStream(), bos);

        @Override
        public void write(int b) throws IOException {
            tee.write(b);
        }
    };
}
 
Example #6
Source File: ContainerExecDecoratorTest.java    From kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
private ProcReturn execCommandInContainer(String containerName, Node node, boolean quiet, String... cmd) throws Exception {
    if (containerName != null && ! containerName.isEmpty()) {
        decorator.setContainerName(containerName);
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Launcher launcher = decorator
            .decorate(new DummyLauncher(new StreamTaskListener(new TeeOutputStream(out, System.out))), node);
    Map<String, String> envs = new HashMap<>(100);
    for (int i = 0; i < 50; i++) {
        envs.put("aaaaaaaa" + i, "bbbbbbbb");
    }
    envs.put("workingDir1", "/home/jenkins/agent");

    ContainerExecProc proc = (ContainerExecProc) launcher
            .launch(launcher.new ProcStarter().pwd("/tmp").cmds(cmd).envs(envs).quiet(quiet));
    // wait for proc to finish (shouldn't take long)
    for (int i = 0; proc.isAlive() && i < 200; i++) {
        Thread.sleep(100);
    }
    assertFalse("proc is alive", proc.isAlive());
    int exitCode = proc.join();
    return new ProcReturn(proc, exitCode, out.toString());
}
 
Example #7
Source File: MCRWebPagesSynchronizer.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns an OuputStream that writes to local webapp and to file inside <code>MCR.WCMS2.DataDir</code>.
 */
public static OutputStream getOutputStream(String path) throws IOException {
    String cleanPath = path.startsWith("/") ? path.substring(1) : path;
    File wcmsDataDir = getWCMSDataDir();
    File webappBaseDir = getWebAppBaseDir();
    File webappTarget = new File(webappBaseDir, cleanPath);
    if (!webappTarget.toPath().startsWith(webappBaseDir.toPath())) {
        throw new IOException(String.format(Locale.ROOT, "Cannot write %s outside the web application: %s",
            webappTarget, webappBaseDir));
    }
    File wcmsDataDirTarget = new File(wcmsDataDir, cleanPath);
    createDirectoryIfNeeded(webappTarget);
    createDirectoryIfNeeded(wcmsDataDirTarget);
    LOGGER.info(String.format(Locale.ROOT, "Writing content to %s and to %s.", webappTarget, wcmsDataDirTarget));
    return new TeeOutputStream(new FileOutputStream(wcmsDataDirTarget), new FileOutputStream(webappTarget));
}
 
Example #8
Source File: ResponseWrapper.java    From app-engine with Apache License 2.0 6 votes vote down vote up
@Override
public ServletOutputStream getOutputStream() throws IOException {
    return new ServletOutputStream() {
        private TeeOutputStream tee = new TeeOutputStream(ResponseWrapper.super.getOutputStream(), bos);

        @Override
        public boolean isReady() {
            return true;
        }

        @Override
        public void setWriteListener(WriteListener writeListener) {
        }

        @Override
        public void write(int b) throws IOException {
            tee.write(b);
        }
    };
}
 
Example #9
Source File: DockerToolInstallerTest.java    From docker-commons-plugin with MIT License 6 votes vote down vote up
private FilePath downloadDocker(DumbSlave slave, FilePath toolDir, String version) throws IOException, InterruptedException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TeeOutputStream tee = new TeeOutputStream(baos, new PlainTextConsoleOutputStream(System.err));
    TaskListener l = new StreamTaskListener(tee);

    FilePath exe = toolDir.child(version+"/bin/docker");
    // Download for first time:
    assertEquals(exe.getRemote(), DockerTool.getExecutable(version, slave, l, null));
    assertTrue(exe.exists());
    assertThat(baos.toString(), containsString(Messages.DockerToolInstaller_downloading_docker_client_(version)));
    // Next time we do not need to download:
    baos.reset();
    assertEquals(exe.getRemote(), DockerTool.getExecutable(version, slave, l, null));
    assertTrue(exe.exists());
    assertThat(baos.toString(), not(containsString(Messages.DockerToolInstaller_downloading_docker_client_(version))));
    // Version check:
    baos.reset();
    assertEquals(0, slave.createLauncher(l).launch().cmds(exe.getRemote(), "version", "--format", "{{.Client.Version}}").quiet(true).stdout(tee).stderr(System.err).join());
    if (!version.equals("latest")) {
        assertEquals(version, baos.toString().trim());
    }
    return exe;
}
 
Example #10
Source File: PrecisionRecallParallel.java    From sequence-mining with GNU General Public License v3.0 5 votes vote down vote up
public static void main(final String[] args) throws IOException, ClassNotFoundException {

		final String baseFolder = "/afs/inf.ed.ac.uk/user/j/jfowkes/Code/Sequences/";
		// final File dbFile = new File(baseFolder + "Datasets/parallel",
		// ".dat");
		// generateParallelDataset(dbFile);

		// Set up logging
		final FileOutputStream outFile = new FileOutputStream(baseFolder + "PrecisionRecall/parallel_pr.txt");
		final TeeOutputStream out = new TeeOutputStream(System.out, outFile);
		final PrintStream ps = new PrintStream(out);
		System.setOut(ps);

		// Read SQS sequences
		final File outSQS = new File(baseFolder + "SQS/parallel_partial.txt");
		final Map<Sequence, Double> seqsSQS = StatisticalSequenceMining.readSQSSequences(outSQS);

		// Read GoKrimp sequences
		final File outGOKRIMP = new File(baseFolder + "GoKrimp/parallel.txt");
		final Map<Sequence, Double> seqsGORKIMP = StatisticalSequenceMining.readGoKrimpSequences(outGOKRIMP);

		// Read ISM sequences
		final File outISM = new File(baseFolder + "Logs/parallel.log");
		final Map<Sequence, Double> seqsISM = SequenceMining.readISMSequences(outISM);

		// Precision-recall
		precisionRecall(seqsSQS, "SQS");
		precisionRecall(seqsGORKIMP, "GoKrimp");
		precisionRecall(seqsISM, "ISM");

	}
 
Example #11
Source File: ForkingGradleHandle.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GradleHandle start() {
    if (execHandle != null) {
        throw new IllegalStateException("you have already called start() on this handle");
    }

    AbstractExecHandleBuilder execBuilder = execHandleFactory.create();
    execBuilder.setStandardOutput(new CloseShieldOutputStream(new TeeOutputStream(System.out, standardOutput)));
    execBuilder.setErrorOutput(new CloseShieldOutputStream(new TeeOutputStream(System.err, errorOutput)));
    execHandle = execBuilder.build();

    execHandle.start();

    return this;
}
 
Example #12
Source File: ForkingGradleHandle.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GradleHandle start() {
    if (execHandle != null) {
        throw new IllegalStateException("you have already called start() on this handle");
    }

    AbstractExecHandleBuilder execBuilder = execHandleFactory.create();
    execBuilder.setStandardOutput(new CloseShieldOutputStream(new TeeOutputStream(System.out, standardOutput)));
    execBuilder.setErrorOutput(new CloseShieldOutputStream(new TeeOutputStream(System.err, errorOutput)));
    execHandle = execBuilder.build();

    execHandle.start();

    return this;
}
 
Example #13
Source File: ExclusiveSequences.java    From sequence-mining with GNU General Public License v3.0 5 votes vote down vote up
public static void main(final String[] args) throws IOException {

		final int topN = 20;
		final String baseDir = "/afs/inf.ed.ac.uk/user/j/jfowkes/Code/Sequences/";
		// final String dataset = "jmlr";
		// final String seqLabels = baseDir + "Datasets/JMLR/jmlr.lab";
		final String dataset = "alice_punc";
		final String seqLabels = baseDir + "Datasets/Alice/WithPunctuation/alice_punc.lab";

		// Set up logging
		final FileOutputStream outFile = new FileOutputStream(baseDir + dataset + "_exclusive.txt");
		final TeeOutputStream out = new TeeOutputStream(System.out, outFile);
		final PrintStream ps = new PrintStream(out);
		System.setOut(ps);

		final Map<Sequence, Double> ismSeqs = SequenceMiningCore
				.readISMSequences(new File(baseDir + "Logs/" + dataset + ".log"));
		final Map<Sequence, Double> sqsSeqs = StatisticalSequenceMining
				.readSQSSequences(new File(baseDir + "SQS/" + dataset + ".txt"));
		final Map<Sequence, Double> gokrimpSeqs = StatisticalSequenceMining
				.readGoKrimpSequences(new File(baseDir + "GoKrimp/" + dataset + ".txt"));

		final Set<Sequence> ISMnotSQSorGoKrimp = getExclusiveSequences(ismSeqs.keySet(), sqsSeqs.keySet(),
				gokrimpSeqs.keySet());
		final Set<Sequence> SQSnotISMorGoKrimp = getExclusiveSequences(sqsSeqs.keySet(), ismSeqs.keySet(),
				gokrimpSeqs.keySet());
		final Set<Sequence> GoKrimpnotISMorSQS = getExclusiveSequences(gokrimpSeqs.keySet(), ismSeqs.keySet(),
				sqsSeqs.keySet());

		final List<String> dict = FileUtils.readLines(new File(seqLabels));

		// Print top ten
		System.out.print("\n============= ISM not SQS/GoKrimp =============\n");
		printTopExclusiveSequences(topN, ismSeqs, ISMnotSQSorGoKrimp, dict);
		System.out.print("\n============= SQS not ISM/GoKrimp =============\n");
		printTopExclusiveSequences(topN, sqsSeqs, SQSnotISMorGoKrimp, dict);
		System.out.print("\n============= GoKrimp not ISM/SQS =============\n");
		printTopExclusiveSequences(topN, gokrimpSeqs, GoKrimpnotISMorSQS, dict);

	}
 
Example #14
Source File: DiagnosticSysOutCapture.java    From synopsys-detect with Apache License 2.0 5 votes vote down vote up
private void captureStdOut() {
    try {
        stdOutStream = new FileOutputStream(stdOutFile);
        final TeeOutputStream myOut = new TeeOutputStream(System.out, stdOutStream);
        final PrintStream ps = new PrintStream(myOut, true); // true - auto-flush after println
        System.setOut(ps);

        logger.info("Writing sysout to file: " + stdOutFile.getCanonicalPath());

    } catch (final Exception e) {
        logger.info("Failed to capture sysout.", e);
    }
}
 
Example #15
Source File: ApplyPreparationExportStrategy.java    From data-prep with Apache License 2.0 5 votes vote down vote up
/**
 * Return the dataset sample.
 *
 * @param parameters the export parameters
 * @param dataSet the sample
 * @param preparationId the id of the corresponding preparation
 *
 */
private void executePipeline(ExportParameters parameters, OutputStream outputStream, TransformationCacheKey key,
        String preparationId, String version, DataSet dataSet) {

    final ExportFormat format = getFormat(parameters.getExportType());
    // get the actions to apply (no preparation ==> dataset export ==> no actions)
    final String actions = getActions(preparationId, version);

    try (final TeeOutputStream tee =
            new TeeOutputStream(outputStream, contentCache.put(key, ContentCache.TimeToLive.DEFAULT))) {
        final Configuration.Builder configurationBuilder = Configuration
                .builder() //
                .args(parameters.getArguments()) //
                .outFilter(rm -> filterService.build(parameters.getFilter(), rm)) //
                .sourceType(parameters.getFrom())
                .format(format.getName()) //
                .actions(actions) //
                .preparation(getPreparation(preparationId)) //
                .stepId(version) //
                .volume(SMALL) //
                .output(tee) //
                .limit(this.limit);

        // no need for statistics if it's not JSON output
        if (!Objects.equals(format.getName(), JSON)) {
            configurationBuilder.globalStatistics(false);
        }

        final Configuration configuration = configurationBuilder.build();

        factory.get(configuration).buildExecutable(dataSet, configuration).execute();

        tee.flush();

    } catch (IOException e1) { // NOSONAR
        LOGGER.debug("evicting cache {}", key.getKey());
        contentCache.evict(key);
        throw new TDPException(TransformationErrorCodes.UNABLE_TO_TRANSFORM_DATASET, e1);
    }
}
 
Example #16
Source File: CommonsIOUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@SuppressWarnings("resource")
@Test
public void whenUsingTeeInputOutputStream_thenWriteto2OutputStreams() throws IOException {

    final String str = "Hello World.";
    ByteArrayInputStream inputStream = new ByteArrayInputStream(str.getBytes());
    ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream();
    ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream();

    FilterOutputStream teeOutputStream = new TeeOutputStream(outputStream1, outputStream2);
    new TeeInputStream(inputStream, teeOutputStream, true).read(new byte[str.length()]);

    Assert.assertEquals(str, String.valueOf(outputStream1));
    Assert.assertEquals(str, String.valueOf(outputStream2));
}
 
Example #17
Source File: AbstractBootstrapTest.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public final void captureStdout() {
    originalStdout = System.out;
    originalStderr = System.err;

    capturedOutputBytes = new ByteArrayOutputStream();
    System.setOut(new PrintStream(new TeeOutputStream(originalStdout, capturedOutputBytes)));
    System.setErr(new PrintStream(new TeeOutputStream(originalStderr, capturedOutputBytes)));
}
 
Example #18
Source File: DiagnosticLogger.java    From hub-detect with Apache License 2.0 5 votes vote down vote up
private void captureStdOut() {
    try {
        stdOutFile = new File(logDirectory, stdOutFilePath);
        stdOutStream = new FileOutputStream(stdOutFile);
        final TeeOutputStream myOut = new TeeOutputStream(System.out, stdOutStream);
        final PrintStream ps = new PrintStream(myOut, true); // true - auto-flush after println
        System.setOut(ps);

        logger.info("Writing sysout to file: " + stdOutFile.getCanonicalPath());

    } catch (final Exception e) {
        logger.info("Failed to capture sysout.", e);
    }
}
 
Example #19
Source File: ForkingGradleHandle.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GradleHandle start() {
    if (execHandle != null) {
        throw new IllegalStateException("you have already called start() on this handle");
    }

    AbstractExecHandleBuilder execBuilder = execHandleFactory.create();
    execBuilder.setStandardOutput(new CloseShieldOutputStream(new TeeOutputStream(System.out, standardOutput)));
    execBuilder.setErrorOutput(new CloseShieldOutputStream(new TeeOutputStream(System.err, errorOutput)));
    execHandle = execBuilder.build();

    execHandle.start();

    return this;
}
 
Example #20
Source File: ForkingGradleHandle.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GradleHandle start() {
    if (execHandle != null) {
        throw new IllegalStateException("you have already called start() on this handle");
    }

    AbstractExecHandleBuilder execBuilder = execHandleFactory.create();
    execBuilder.setStandardOutput(new CloseShieldOutputStream(new TeeOutputStream(System.out, standardOutput)));
    execBuilder.setErrorOutput(new CloseShieldOutputStream(new TeeOutputStream(System.err, errorOutput)));
    execHandle = execBuilder.build();

    execHandle.start();

    return this;
}
 
Example #21
Source File: HttpSnifferFilter.java    From training with MIT License 4 votes vote down vote up
public TeeServletOutputStream( OutputStream one, OutputStream two ) {
	targetStream = new TeeOutputStream( one, two);
}
 
Example #22
Source File: HttpLoggingFilter.java    From swagger-aem with Apache License 2.0 4 votes vote down vote up
public TeeServletOutputStream(OutputStream one, OutputStream two) {
  targetStream = new TeeOutputStream(one, two);
}
 
Example #23
Source File: TeeStep.java    From pipeline-utility-steps-plugin with MIT License 4 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public OutputStream decorateLogger(Run build, final OutputStream logger) throws IOException, InterruptedException {
    return new TeeOutputStream(logger, stream = append(f, stream));
}
 
Example #24
Source File: TeeOutputContainer.java    From pygradle with Apache License 2.0 4 votes vote down vote up
public TeeOutputContainer(OutputStream stdOut, OutputStream errOut) {
    teeStdOut = new TeeOutputStream(stdOut, mergedStream);
    teeErrOut = new TeeOutputStream(errOut, mergedStream);
}
 
Example #25
Source File: IOUtils.java    From gradle-golang-plugin with Mozilla Public License 2.0 4 votes vote down vote up
@Nonnull
public static StdStreams tee(@Nonnull StdStreams a, @Nonnull StdStreams b) {
    final OutputStream out = new TeeOutputStream(a.out(), b.out());
    final OutputStream err = new TeeOutputStream(a.err(), b.err());
    return new Impl(out, err);
}
 
Example #26
Source File: ParsecServletResponseWrapper.java    From parsec-libraries with Apache License 2.0 4 votes vote down vote up
DelegatedServletOutputStream(ServletOutputStream servletStream) {
    this.servletStream = servletStream;
    teeStream = new TeeOutputStream(servletStream, contentStream);
}
 
Example #27
Source File: ThreadLocalPrintStream.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/** creates a capturing context which sees the output to this stream, without interrupting the original target */
public OutputCapturingContext captureTee() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PrintStream toRestore = setThreadLocalPrintStream(new TeeOutputStream(getDelegate(), out));
    return new OutputCapturingContext(this, out, toRestore);
}
 
Example #28
Source File: SequenceSymmetricDistance.java    From sequence-mining with GNU General Public License v3.0 4 votes vote down vote up
public static void main(final String[] args) throws IOException {

		// TODO re-run BIDE...
		final int topN = 50;
		final String baseDir = "/afs/inf.ed.ac.uk/user/j/jfowkes/Code/Sequences/";
		final String[] datasets = new String[] { "alice_punc", "GAZELLE1", "jmlr", "SIGN", "aslbu", "aslgt", "auslan2",
				"context", "pioneer", "skating" };

		// Set up logging
		final FileOutputStream outFile = new FileOutputStream(baseDir + "redundancy.txt");
		final TeeOutputStream out = new TeeOutputStream(System.out, outFile);
		final PrintStream ps = new PrintStream(out);
		System.setOut(ps);

		final Writer writer = Files.newWriter(new File(baseDir + "redundancy.tex"), Charsets.UTF_8);

		for (int i = 0; i < datasets.length; i++) {

			System.out.println("===== Dataset: " + datasets[i]);

			// ISM sequences
			final Map<Sequence, Double> intSequences = SequenceMiningCore
					.readISMSequences(new File(baseDir + "Logs/" + datasets[i] + ".log"));
			calculateRedundancyStats("ISM", intSequences, topN, writer);

			// SQS sequences
			final Map<Sequence, Double> sqsSequences = StatisticalSequenceMining
					.readSQSSequences(new File(baseDir + "SQS/" + datasets[i] + ".txt"));
			calculateRedundancyStats("SQS", sqsSequences, topN, writer);

			// GoKrimp sequences
			final Map<Sequence, Double> gokrimpSequences = StatisticalSequenceMining
					.readGoKrimpSequences(new File(baseDir + "GoKrimp/" + datasets[i] + ".txt"));
			calculateRedundancyStats("GoKrimp", gokrimpSequences, topN, writer);

			// BIDE sequences
			final Map<Sequence, Integer> bideSequences = FrequentSequenceMining
					.readFrequentSequences(new File(baseDir + "BIDE/" + datasets[i] + ".txt"));
			calculateRedundancyStats("BIDE", bideSequences, topN, writer);

			System.out.println();
		}
		writer.close();

	}
 
Example #29
Source File: HttpLoggingFilter.java    From swaggy-jenkins with MIT License 4 votes vote down vote up
public TeeServletOutputStream(OutputStream one, OutputStream two) {
  targetStream = new TeeOutputStream(one, two);
}
 
Example #30
Source File: SequenceScaling.java    From sequence-mining with GNU General Public License v3.0 4 votes vote down vote up
public static void scalingTransactions(final int noCores, final int[] trans)
		throws IOException, ClassNotFoundException {

	final double[] time = new double[trans.length];
	final DecimalFormat formatter = new DecimalFormat("0.0E0");

	// Save to file
	final FileOutputStream outFile = new FileOutputStream(saveDir + "/" + name + "_scaling_" + noCores + ".txt");
	final TeeOutputStream out = new TeeOutputStream(System.out, outFile);
	final PrintStream ps = new PrintStream(out);
	System.setOut(ps);

	// Read in previously mined sequences
	final Map<Sequence, Double> sequences = SequenceMiningCore.readISMSequences(sequenceLog);
	System.out.print("\n============= ACTUAL SEQUENCES =============\n");
	for (final Entry<Sequence, Double> entry : sequences.entrySet()) {
		System.out.print(String.format("%s\tprob: %1.5f %n", entry.getKey(), entry.getValue()));
	}
	System.out.println("\nNo sequences: " + sequences.size());
	System.out.println("No items: " + countNoItems(sequences.keySet()));

	// Read in associated sequence count distribution
	@SuppressWarnings("unchecked")
	final Table<Sequence, Integer, Double> countDist = (Table<Sequence, Integer, Double>) Logging
			.deserializeFrom(FilenameUtils.removeExtension(sequenceLog.getAbsolutePath()) + ".dist");

	transloop: for (int i = 0; i < trans.length; i++) {

		final int tran = trans[i];
		System.out.println("\n========= " + formatter.format(tran) + " Transactions");

		// Generate transaction database
		TransactionGenerator.generateTransactionDatabase(sequences, countDist, tran, dbFile);
		SequenceScaling.printTransactionDBStats(dbFile);

		// Mine sequences
		final File logFile = Logging.getLogFileName("ISM", true, saveDir, dbFile);
		final long startTime = System.currentTimeMillis();
		SequenceMining.mineSequences(dbFile, new InferGreedy(), maxStructureSteps, maxEMIterations, logFile, false);

		final long endTime = System.currentTimeMillis();
		final double tim = (endTime - startTime) / (double) 1000;
		time[i] += tim;

		System.out.printf("Time (s): %.2f%n", tim);

		if (tim > MAX_RUNTIME * 60)
			break transloop;

	}

	// Print time
	System.out.println("\n========" + name + "========");
	System.out.println("Transactions:" + Arrays.toString(trans));
	System.out.println("Time: " + Arrays.toString(time));

	// and save to file
	out.close();
}