| 1 | /** |
| 2 | * BSD-style license; for more info see http://xradar.sourceforge.net/license.html |
| 3 | */ |
| 4 | package org.sourceforge.xradar.statics; |
| 5 | |
| 6 | import java.io.FileInputStream; |
| 7 | import java.io.FileNotFoundException; |
| 8 | import java.io.IOException; |
| 9 | import java.io.InputStream; |
| 10 | |
| 11 | /** |
| 12 | * @author rpelisse |
| 13 | * |
| 14 | */ |
| 15 | public class MergeProduct |
| 16 | { |
| 17 | private static final int EOF = -1; |
| 18 | |
| 19 | private InputStream radarNormalized; |
| 20 | private InputStream masterReport; |
| 21 | private InputStream systemQuality; |
| 22 | |
| 23 | private String radarNormalizedFilename; |
| 24 | private String masterReportFilename; |
| 25 | private String systemQualityFilename; |
| 26 | |
| 27 | private InputStream rebuildFileInputStream(InputStream stream,String filename) { |
| 28 | try |
| 29 | { |
| 30 | stream = new FileInputStream(filename); |
| 31 | } |
| 32 | catch (FileNotFoundException fileNotFoundException) |
| 33 | { |
| 34 | // well, this should never happens... :) |
| 35 | stream = null; |
| 36 | } |
| 37 | return stream; |
| 38 | } |
| 39 | |
| 40 | private InputStream returnStream(InputStream stream,String filename) { |
| 41 | |
| 42 | if ( stream.markSupported() ) { |
| 43 | stream.mark(1); |
| 44 | try { |
| 45 | if ( stream.read() == EOF ) |
| 46 | { |
| 47 | stream = this.rebuildFileInputStream(stream, filename); |
| 48 | } |
| 49 | else |
| 50 | { |
| 51 | stream.reset(); |
| 52 | } |
| 53 | } |
| 54 | catch (IOException error ) { |
| 55 | // this should never happens ! |
| 56 | stream = this.rebuildFileInputStream(stream, filename); |
| 57 | } |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | try |
| 62 | { |
| 63 | stream.available(); // throw an exception if stream invalid so ... |
| 64 | } |
| 65 | catch (IOException e) |
| 66 | { |
| 67 | // ... we created again the stream |
| 68 | stream = this.rebuildFileInputStream(stream, filename); |
| 69 | } |
| 70 | } |
| 71 | return stream; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | /** |
| 76 | * @return the radarNormalized |
| 77 | */ |
| 78 | public InputStream getRadarNormalized() { |
| 79 | return this.returnStream(radarNormalized,radarNormalizedFilename); |
| 80 | } |
| 81 | /** |
| 82 | * @param radarNormalized the radarNormalized to set |
| 83 | */ |
| 84 | public void setRadarNormalized(InputStream radarNormalized) { |
| 85 | this.radarNormalized = radarNormalized; |
| 86 | } |
| 87 | /** |
| 88 | * @return the masterReport |
| 89 | */ |
| 90 | public InputStream getMasterReport() { |
| 91 | return this.returnStream(masterReport,masterReportFilename); |
| 92 | } |
| 93 | /** |
| 94 | * @param masterReport the masterReport to set |
| 95 | */ |
| 96 | public void setMasterReport(InputStream masterReport) { |
| 97 | this.masterReport = masterReport; |
| 98 | } |
| 99 | /** |
| 100 | * @return the systemQuality |
| 101 | */ |
| 102 | public InputStream getSystemQuality() { |
| 103 | return this.returnStream(systemQuality,systemQualityFilename); |
| 104 | } |
| 105 | /** |
| 106 | * @param systemQuality the systemQuality to set |
| 107 | */ |
| 108 | public void setSystemQuality(InputStream systemQuality) { |
| 109 | this.systemQuality = systemQuality; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @return the radarNormalizedFilename |
| 114 | */ |
| 115 | public String getRadarNormalizedFilename() { |
| 116 | return radarNormalizedFilename; |
| 117 | } |
| 118 | /** |
| 119 | * @param radarNormalizedFilename the radarNormalizedFilename to set |
| 120 | */ |
| 121 | public void setRadarNormalizedFilename(String radarNormalizedFilename) { |
| 122 | this.radarNormalizedFilename = radarNormalizedFilename; |
| 123 | } |
| 124 | /** |
| 125 | * @return the masterReportFilename |
| 126 | */ |
| 127 | public String getMasterReportFilename() { |
| 128 | return masterReportFilename; |
| 129 | } |
| 130 | /** |
| 131 | * @param masterReportFilename the masterReportFilename to set |
| 132 | */ |
| 133 | public void setMasterReportFilename(String masterReportFilename) { |
| 134 | this.masterReportFilename = masterReportFilename; |
| 135 | } |
| 136 | /** |
| 137 | * @return the systemQualityFilename |
| 138 | */ |
| 139 | public String getSystemQualityFilename() { |
| 140 | return systemQualityFilename; |
| 141 | } |
| 142 | /** |
| 143 | * @param systemQualityFilename the systemQualityFilename to set |
| 144 | */ |
| 145 | public void setSystemQualityFilename(String systemQualityFilename) { |
| 146 | this.systemQualityFilename = systemQualityFilename; |
| 147 | } |
| 148 | |
| 149 | } |