FileMultiReportOutput.java
1/*******************************************************************************
2 * Copyright (c) 2009 Mountainminds GmbH & Co. KG and others
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Marc R. Hoffmann - initial API and implementation
10 *
11 * $Id: $
12 *******************************************************************************/
13package org.jacoco.report;
14
15import static java.lang.String.format;
16
17import java.io.BufferedOutputStream;
18import java.io.File;
19import java.io.FileOutputStream;
20import java.io.IOException;
21import java.io.OutputStream;
22
23/**
24 * Implementation of {@link IMultiReportOutput} that writes files directly to a
25 * given directory.
26 *
27 * @author Marc R. Hoffmann
28 * @version $Revision: $
29 */
30public class FileMultiReportOutput implements IMultiReportOutput {
31
32 private final File basedir;
33
34 /**
35 * Creates a new instance for document output in the given base directory.
36 *
37 * @param basedir
38 */
39 public FileMultiReportOutput(final File basedir) {
40 this.basedir = basedir;
41 }
42
43 public OutputStream createFile(final String path) throws IOException {
44 final File file = new File(basedir, path);
45 final File parent = file.getParentFile();
46 parent.mkdirs();
47 if (!parent.isDirectory()) {
48 throw new IOException(format("Can't create directory %s.", parent));
49 }
50 return new BufferedOutputStream(new FileOutputStream(file));
51 }
52
53}