| 1 |
|
package com.atlassian.core.spool; |
| 2 |
|
|
| 3 |
|
import java.io.*; |
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
|
|
|
| 70.6% |
Uncovered Elements: 10 (34) |
Complexity: 11 |
Complexity Density: 0.55 |
|
| 10 |
|
public class DeferredSpoolFileOutputStream extends DeferredFileOutputStream |
| 11 |
|
{ |
| 12 |
|
private FileFactory fileFactory = DefaultSpoolFileFactory.getInstance(); |
| 13 |
|
private boolean unspooling = false; |
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
@see |
| 18 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 19 |
0
|
public DeferredSpoolFileOutputStream(int threshold, File outputFile)... |
| 20 |
|
{ |
| 21 |
0
|
super(threshold, outputFile); |
| 22 |
|
} |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
@param |
| 28 |
|
@param |
| 29 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 30 |
2
|
public DeferredSpoolFileOutputStream(int threshold, FileFactory fileFactory)... |
| 31 |
|
{ |
| 32 |
2
|
super(threshold, null); |
| 33 |
2
|
this.fileFactory = fileFactory; |
| 34 |
|
} |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@return |
| 38 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 39 |
1
|
public boolean isClosed()... |
| 40 |
|
{ |
| 41 |
1
|
return closed; |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@return |
| 47 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 48 |
1
|
public boolean isUnspooling()... |
| 49 |
|
{ |
| 50 |
1
|
return unspooling; |
| 51 |
|
} |
| 52 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 53 |
1
|
protected void thresholdReached() throws IOException... |
| 54 |
|
{ |
| 55 |
1
|
if (outputFile == null) |
| 56 |
1
|
outputFile = fileFactory.createNewFile(); |
| 57 |
1
|
super.thresholdReached(); |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
@return |
| 65 |
|
|
| 66 |
|
@throws |
| 67 |
|
|
|
|
|
| 61.1% |
Uncovered Elements: 7 (18) |
Complexity: 5 |
Complexity Density: 0.42 |
|
| 68 |
1
|
public InputStream getInputStream() throws IOException... |
| 69 |
|
{ |
| 70 |
1
|
if (!isClosed()) |
| 71 |
0
|
throw new IOException("Output stream not closed"); |
| 72 |
|
|
| 73 |
1
|
if (isUnspooling()) |
| 74 |
0
|
throw new IOException("Stream is already being unspooled"); |
| 75 |
|
|
| 76 |
1
|
InputStream spoolStream; |
| 77 |
|
|
| 78 |
1
|
if (isInMemory()) |
| 79 |
0
|
spoolStream = new ByteArrayInputStream(getData()); |
| 80 |
|
else |
| 81 |
1
|
try |
| 82 |
|
{ |
| 83 |
1
|
spoolStream = new SpoolFileInputStream(getFile()); |
| 84 |
|
} |
| 85 |
|
catch (FileNotFoundException ex) |
| 86 |
|
{ |
| 87 |
0
|
throw new IOException("Deferred file does not exist"); |
| 88 |
|
} |
| 89 |
|
|
| 90 |
1
|
unspooling = true; |
| 91 |
1
|
return spoolStream; |
| 92 |
|
} |
| 93 |
|
} |