| 1 | /* |
| 2 | * JTiger Unit Testing Framework for J2SE 1.5 |
| 3 | * Copyright (C) 2005 Tony Morris |
| 4 | * |
| 5 | * This software is licenced under the |
| 6 | * Common Public Licence version 1.0 |
| 7 | * http://www.opensource.org/licenses/cpl1.0.php |
| 8 | * |
| 9 | * You received a copy of this licence with this software. |
| 10 | */ |
| 11 | package org.jtiger.report.html; |
| 12 | |
| 13 | import java.io.File; |
| 14 | import java.io.FileOutputStream; |
| 15 | import java.io.IOException; |
| 16 | import java.io.InputStream; |
| 17 | import java.io.OutputStream; |
| 18 | import org.jtiger.framework.FixtureResultsHandlerException; |
| 19 | |
| 20 | final class IndexHtmlFileWriterFactory |
| 21 | { |
| 22 | private IndexHtmlFileWriterFactory() |
| 23 | { |
| 24 | |
| 25 | } |
| 26 | |
| 27 | static IndexHtmlFileWriter newIndexHtmlFileWriter() |
| 28 | { |
| 29 | return new IndexHtmlFileWriterImpl(); |
| 30 | } |
| 31 | |
| 32 | private static final class IndexHtmlFileWriterImpl implements IndexHtmlFileWriter |
| 33 | { |
| 34 | IndexHtmlFileWriterImpl() |
| 35 | { |
| 36 | |
| 37 | } |
| 38 | |
| 39 | public void writeIndexHtmlFile(final File destination) throws FixtureResultsHandlerException |
| 40 | { |
| 41 | final File f = new File(destination, "index.html"); |
| 42 | |
| 43 | OutputStream out = null; |
| 44 | |
| 45 | try |
| 46 | { |
| 47 | out = new FileOutputStream(f); |
| 48 | InputStream in = null; |
| 49 | |
| 50 | try |
| 51 | { |
| 52 | in = getClass().getResourceAsStream("/org/jtiger/report/html/index.html"); |
| 53 | final byte[] buffer = new byte[4096]; |
| 54 | int len; |
| 55 | |
| 56 | while((len = in.read(buffer)) != -1) |
| 57 | { |
| 58 | out.write(buffer, 0, len); |
| 59 | } |
| 60 | } |
| 61 | finally |
| 62 | { |
| 63 | if(in != null) |
| 64 | { |
| 65 | try |
| 66 | { |
| 67 | in.close(); |
| 68 | } |
| 69 | catch(IOException e) |
| 70 | { |
| 71 | throw new FixtureResultsHandlerException(e.getMessage(), e); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | catch(IOException e) |
| 77 | { |
| 78 | throw new FixtureResultsHandlerException(e.getMessage(), e); |
| 79 | } |
| 80 | finally |
| 81 | { |
| 82 | if(out != null) |
| 83 | { |
| 84 | try |
| 85 | { |
| 86 | out.close(); |
| 87 | } |
| 88 | catch(IOException e) |
| 89 | { |
| 90 | throw new FixtureResultsHandlerException(e.getMessage(), e); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |