001 /** 002 * www.jcoverage.com 003 * Copyright (C)2003 jcoverage ltd. 004 * 005 * This file is part of jcoverage. 006 * 007 * jcoverage is free software; you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published 009 * by the Free Software Foundation; either version 2 of the License, 010 * or (at your option) any later version. 011 * 012 * jcoverage is distributed in the hope that it will be useful, but 013 * WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with jcoverage; if not, write to the Free Software 019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 020 * USA 021 * 022 */ 023 package com.jcoverage.reporting; 024 025 import java.io.*; 026 027 import org.apache.log4j.Logger; 028 029 import com.jcoverage.reporting.Serializer; 030 031 /** 032 * 033 */ 034 public class FileSerializer implements Serializer { 035 036 static Logger logger=Logger.getLogger(FileSerializer.class); 037 038 File baseDirectory; 039 040 public FileSerializer(File baseDirectory) { 041 this.baseDirectory=baseDirectory; 042 } 043 044 public Writer getWriterForPath(String path) throws ReportingException { 045 try { 046 File f=new File(baseDirectory,path); 047 f.getParentFile().mkdirs(); 048 return new FileWriter(f); 049 } catch(IOException ex) { 050 throw new ReportingException("Failed to create file writer",ex); 051 } 052 } 053 054 }