| 1 |
|
package com.atlassian.core.spool; |
| 2 |
|
|
| 3 |
|
import org.apache.log4j.Category; |
| 4 |
|
|
| 5 |
|
import java.io.*; |
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
|
|
|
| 40% |
Uncovered Elements: 30 (50) |
Complexity: 16 |
Complexity Density: 0.55 |
|
| 13 |
|
public class SpoolFileInputStream extends FileInputStream { |
| 14 |
|
|
| 15 |
|
private static final Category log = Category.getInstance(SpoolFileInputStream.class); |
| 16 |
|
|
| 17 |
|
private File fileToDelete; |
| 18 |
|
|
| 19 |
|
private boolean closed = false; |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
@param |
| 23 |
|
@throws |
| 24 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 25 |
3
|
public SpoolFileInputStream(File file) throws FileNotFoundException... |
| 26 |
|
{ |
| 27 |
3
|
super(file); |
| 28 |
3
|
init(file); |
| 29 |
|
} |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
@param |
| 33 |
|
@throws |
| 34 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 35 |
0
|
public SpoolFileInputStream(String name) throws FileNotFoundException... |
| 36 |
|
{ |
| 37 |
0
|
super(name); |
| 38 |
0
|
init(new File(name)); |
| 39 |
|
} |
| 40 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 41 |
3
|
private void init(File file)... |
| 42 |
|
{ |
| 43 |
3
|
this.fileToDelete = file; |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
@see |
| 48 |
|
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 49 |
6
|
public void close() throws IOException... |
| 50 |
|
{ |
| 51 |
6
|
try { |
| 52 |
6
|
closed = true; |
| 53 |
6
|
super.close(); |
| 54 |
|
} |
| 55 |
|
catch (IOException ex) |
| 56 |
|
{ |
| 57 |
0
|
log.error("Error closing spool stream", ex); |
| 58 |
|
} |
| 59 |
|
finally |
| 60 |
|
{ |
| 61 |
6
|
if (fileToDelete.exists() && !fileToDelete.delete()) |
| 62 |
|
{ |
| 63 |
0
|
log.warn("Could not delete spool file " + fileToDelete); |
| 64 |
|
} |
| 65 |
|
} |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 68 |
0
|
public int read() throws IOException... |
| 69 |
|
{ |
| 70 |
0
|
if (closed) |
| 71 |
|
{ |
| 72 |
0
|
return -1; |
| 73 |
|
} |
| 74 |
0
|
int n = super.read(); |
| 75 |
0
|
if (n == -1) |
| 76 |
|
{ |
| 77 |
0
|
close(); |
| 78 |
|
} |
| 79 |
0
|
return n; |
| 80 |
|
} |
| 81 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 82 |
0
|
public int read(byte b[]) throws IOException... |
| 83 |
|
{ |
| 84 |
0
|
if (closed) |
| 85 |
|
{ |
| 86 |
0
|
return -1; |
| 87 |
|
} |
| 88 |
0
|
int n = super.read(b); |
| 89 |
0
|
if (n == -1) |
| 90 |
|
{ |
| 91 |
0
|
close(); |
| 92 |
|
} |
| 93 |
0
|
return n; } |
| 94 |
|
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 95 |
8
|
public int read(byte b[], int off, int len) throws IOException... |
| 96 |
|
{ |
| 97 |
8
|
if (closed) |
| 98 |
|
{ |
| 99 |
0
|
return -1; |
| 100 |
|
} |
| 101 |
8
|
int n = super.read(b, off, len); |
| 102 |
8
|
if (n == -1) |
| 103 |
|
{ |
| 104 |
2
|
close(); |
| 105 |
|
} |
| 106 |
8
|
return n; |
| 107 |
|
} |
| 108 |
|
} |