Paul Duffin | e236301 | 2015-11-30 16:20:41 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2014 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.google.caliper.runner; |
| 18 | |
| 19 | import java.io.File; |
| 20 | import java.io.FileNotFoundException; |
| 21 | import java.io.PrintWriter; |
| 22 | |
| 23 | /** |
| 24 | * A factory for trial log files. |
| 25 | * |
| 26 | * <p>The log files may be configured to be deleted on exit of the runner process. If the files |
| 27 | * should not be deleted then call {@link #persistFile(File)} to ensure that they survive. |
| 28 | */ |
| 29 | interface TrialOutputFactory { |
| 30 | |
| 31 | /** A simple tuple of a {@link File} and a {@link PrintWriter} for writing to that file. */ |
| 32 | final class FileAndWriter { |
| 33 | final File file; |
| 34 | final PrintWriter writer; |
| 35 | |
| 36 | FileAndWriter(File file, PrintWriter writer) { |
| 37 | this.file = file; |
| 38 | this.writer = writer; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /** Returns the file to write trial output to. */ |
| 43 | FileAndWriter getTrialOutputFile(int trialNumber) throws FileNotFoundException; |
| 44 | |
| 45 | /** |
| 46 | * Ensures that the given file will not be deleted after the run. The file provided must be equal |
| 47 | * to a file returned by {@link #getTrialOutputFile(int)}. |
| 48 | */ |
| 49 | void persistFile(File f); |
| 50 | } |