| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.qedeq.base.io; |
| 17 |
|
|
| 18 |
|
import java.io.ByteArrayInputStream; |
| 19 |
|
import java.io.File; |
| 20 |
|
import java.io.FileFilter; |
| 21 |
|
import java.io.FileInputStream; |
| 22 |
|
import java.io.FileNotFoundException; |
| 23 |
|
import java.io.FileOutputStream; |
| 24 |
|
import java.io.FileReader; |
| 25 |
|
import java.io.FileWriter; |
| 26 |
|
import java.io.IOException; |
| 27 |
|
import java.io.InputStream; |
| 28 |
|
import java.io.InputStreamReader; |
| 29 |
|
import java.io.OutputStream; |
| 30 |
|
import java.io.Reader; |
| 31 |
|
import java.io.UnsupportedEncodingException; |
| 32 |
|
import java.io.Writer; |
| 33 |
|
import java.util.Random; |
| 34 |
|
|
| 35 |
|
import org.qedeq.base.test.QedeqTestCase; |
| 36 |
|
import org.qedeq.base.utility.EqualsUtility; |
| 37 |
|
import org.qedeq.base.utility.StringUtility; |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@link |
| 41 |
|
|
| 42 |
|
@author |
| 43 |
|
|
|
|
|
| 86.3% |
Uncovered Elements: 102 (744) |
Complexity: 112 |
Complexity Density: 0.2 |
|
| 44 |
|
public class IoUtilityTest extends QedeqTestCase { |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
@see |
| 49 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 50 |
30
|
protected void setUp() throws Exception {... |
| 51 |
30
|
super.setUp(); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
@see |
| 56 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 57 |
30
|
protected void tearDown() throws Exception {... |
| 58 |
30
|
super.tearDown(); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
|
| 62 |
|
@link |
| 63 |
|
|
| 64 |
|
@throws |
| 65 |
|
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
1
PASS
|
|
| 66 |
1
|
public void testGetDefaultEncoding() throws Exception {... |
| 67 |
1
|
assertEquals(System.getProperty("file.encoding"), IoUtility.getDefaultEncoding()); |
| 68 |
1
|
final String encoding = new InputStreamReader(new ByteArrayInputStream( |
| 69 |
|
new byte[0])).getEncoding(); |
| 70 |
|
|
| 71 |
1
|
if (!StringUtility.replace(System.getProperty("file.encoding"), "-", "").equals(encoding)) { |
| 72 |
1
|
System.out.println("This system showed the java property \"file.encoding\" " |
| 73 |
|
+ System.getProperty("file.encoding") + " but the detected writing default is: " |
| 74 |
|
+ "\"" + IoUtility.getDefaultEncoding() |
| 75 |
|
+ "\"\nThis might be ok, but you should check it"); |
| 76 |
|
} |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
@link |
| 81 |
|
|
| 82 |
|
@throws |
| 83 |
|
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
1
PASS
|
|
| 84 |
1
|
public void testLoadFileStringString() throws Exception {... |
| 85 |
1
|
final File file = new File("IoUtilityTestLoadStringString.txt"); |
| 86 |
1
|
if (file.exists()) { |
| 87 |
0
|
assertTrue(file.delete()); |
| 88 |
|
} |
| 89 |
1
|
IoUtility.saveFileBinary(file, StringUtility.hex2byte( |
| 90 |
|
"FF FE 49 00 20 00 61 00 6D 00 20 00 64 00 72 00" |
| 91 |
|
+ "65 00 61 00 6D 00 69 00 6E 00 67 00 20 00 6F 00" |
| 92 |
|
+ "66 00 20 00 61 00 20 00 77 00 68 00 69 00 74 00" |
| 93 |
|
+ "65 00 20 00 63 00 68 00 72 00 69 00 73 00 74 00" |
| 94 |
|
+ "6D 00 61 00 73 00 73 00 2E 00 2E 00 2E 00")); |
| 95 |
1
|
assertEquals("I am dreaming of a white christmass...", IoUtility.loadFile(file.toString(), |
| 96 |
|
"UTF16")); |
| 97 |
1
|
assertTrue(file.delete()); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
@link |
| 102 |
|
|
| 103 |
|
@throws |
| 104 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
| 105 |
1
|
public void testGetWorkingEncoding() throws Exception {... |
| 106 |
1
|
assertEquals("ISO-8859-1", IoUtility.getWorkingEncoding("unknown")); |
| 107 |
1
|
System.err.println("^ above text is ok, this was intended test behaviour"); |
| 108 |
1
|
assertEquals("UTF-8", IoUtility.getWorkingEncoding("UTF-8")); |
| 109 |
1
|
assertEquals("UTF-16", IoUtility.getWorkingEncoding("UTF-16")); |
| 110 |
1
|
assertEquals("UTF8", IoUtility.getWorkingEncoding("UTF8")); |
| 111 |
1
|
assertEquals("ISO-8859-1", IoUtility.getWorkingEncoding(null)); |
| 112 |
1
|
System.err.println("^ above text is ok, this was intended test behaviour"); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
|
| 116 |
|
@link |
| 117 |
|
|
| 118 |
|
@throws |
| 119 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 120 |
1
|
public void testCreateRelativePath() throws Exception {... |
| 121 |
1
|
assertEquals("local", IoUtility.createRelativePath(new File("."), new File("local"))); |
| 122 |
1
|
assertEquals("text", IoUtility.createRelativePath(new File("/local/data"), |
| 123 |
|
new File("/local/data/text"))); |
| 124 |
1
|
assertEquals("../../green", IoUtility.createRelativePath(new File("/local/data"), |
| 125 |
|
new File("/green"))); |
| 126 |
1
|
assertEquals("../green", IoUtility.createRelativePath(new File("/local/data"), |
| 127 |
|
new File("/local/green"))); |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
@link |
| 132 |
|
|
| 133 |
|
@throws |
| 134 |
|
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
1
PASS
|
|
| 135 |
1
|
public void testLoadStreamInputStreamStringBuffer() throws Exception {... |
| 136 |
1
|
final File file = new File("testLoadStreamInputStreamStringBuffer.txt"); |
| 137 |
1
|
if (file.exists()) { |
| 138 |
0
|
assertTrue(file.delete()); |
| 139 |
|
} |
| 140 |
1
|
final OutputStream out = new FileOutputStream(file); |
| 141 |
1
|
final String expected = "We all live in a yellow submarine ..."; |
| 142 |
1
|
out.write(expected.getBytes()); |
| 143 |
1
|
out.close(); |
| 144 |
1
|
final StringBuffer buffer = new StringBuffer(); |
| 145 |
1
|
final InputStream in = new FileInputStream(file); |
| 146 |
1
|
IoUtility.loadStream(in, buffer); |
| 147 |
1
|
in.close(); |
| 148 |
1
|
assertEquals(expected, buffer.toString()); |
| 149 |
1
|
assertTrue(file.delete()); |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
|
| 153 |
|
@link |
| 154 |
|
|
| 155 |
|
@throws |
| 156 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 157 |
1
|
public void testLoadStreamWithoutException() throws Exception {... |
| 158 |
1
|
final String expected = "We all live in a yellow submarine ..."; |
| 159 |
1
|
assertEquals("", IoUtility.loadStreamWithoutException(null, 100)); |
| 160 |
1
|
assertEquals("", IoUtility.loadStreamWithoutException(null, -100)); |
| 161 |
1
|
assertEquals("", IoUtility.loadStreamWithoutException(new InputStream() { |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 162 |
0
|
public int read() throws IOException {... |
| 163 |
0
|
throw new IOException("i am an error input stream!"); |
| 164 |
|
} |
| 165 |
|
}, 0)); |
| 166 |
1
|
assertEquals("", IoUtility.loadStreamWithoutException(new InputStream() { |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 167 |
0
|
public int read() throws IOException {... |
| 168 |
0
|
throw new IOException("i am an error input stream!"); |
| 169 |
|
} |
| 170 |
|
}, -99)); |
| 171 |
1
|
assertEquals(expected, streamLoad(expected, expected.length())); |
| 172 |
1
|
assertEquals(expected, streamLoad(expected, expected.length() * 100)); |
| 173 |
1
|
assertEquals(expected.substring(0, expected.length() - 1), |
| 174 |
|
streamLoad(expected, expected.length() - 1)); |
| 175 |
1
|
assertEquals(expected.substring(0, 1), |
| 176 |
|
streamLoad(expected, 1)); |
| 177 |
1
|
assertEquals("", streamLoad(expected, -2)); |
| 178 |
|
|
| 179 |
|
} |
| 180 |
|
|
|
|
|
| 81% |
Uncovered Elements: 4 (21) |
Complexity: 4 |
Complexity Density: 0.27 |
|
| 181 |
5
|
private String streamLoad(final String expected, final int length) throws IOException {... |
| 182 |
5
|
final File file = new File("testLoadStreamWithoutException.txt"); |
| 183 |
5
|
if (file.exists()) { |
| 184 |
0
|
assertTrue(file.delete()); |
| 185 |
|
} |
| 186 |
5
|
try { |
| 187 |
5
|
final OutputStream out = new FileOutputStream(file); |
| 188 |
5
|
try { |
| 189 |
5
|
out.write(expected.getBytes()); |
| 190 |
|
} finally { |
| 191 |
5
|
if (out != null) { |
| 192 |
5
|
out.close(); |
| 193 |
|
} |
| 194 |
|
} |
| 195 |
5
|
final InputStream in = new FileInputStream(file); |
| 196 |
5
|
try { |
| 197 |
5
|
return IoUtility.loadStreamWithoutException(in, length); |
| 198 |
|
} finally { |
| 199 |
5
|
if (in != null) { |
| 200 |
|
|
| 201 |
5
|
in.close(); |
| 202 |
|
} |
| 203 |
|
} |
| 204 |
|
} finally { |
| 205 |
5
|
assertTrue(file.delete()); |
| 206 |
|
} |
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
|
| 210 |
|
@link |
| 211 |
|
|
| 212 |
|
@throws |
| 213 |
|
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
1
PASS
|
|
| 214 |
1
|
public void testLoadReader() throws Exception {... |
| 215 |
1
|
final File file = new File("testLoadReaderStringBuffer.txt"); |
| 216 |
1
|
if (file.exists()) { |
| 217 |
0
|
assertTrue(file.delete()); |
| 218 |
|
} |
| 219 |
1
|
final Writer out = new FileWriter(file); |
| 220 |
1
|
final String expected = "We all live in a yellow submarine ..."; |
| 221 |
1
|
out.write(expected); |
| 222 |
1
|
out.close(); |
| 223 |
1
|
final StringBuffer buffer = new StringBuffer(); |
| 224 |
1
|
final Reader in = new FileReader(file); |
| 225 |
1
|
IoUtility.loadReader(in, buffer); |
| 226 |
|
|
| 227 |
1
|
in.close(); |
| 228 |
1
|
assertEquals(expected, buffer.toString()); |
| 229 |
1
|
assertTrue(file.delete()); |
| 230 |
|
} |
| 231 |
|
|
| 232 |
|
|
| 233 |
|
@link |
| 234 |
|
|
| 235 |
|
@throws |
| 236 |
|
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
1
PASS
|
|
| 237 |
1
|
public void testLoadFileFileStringBuffer() throws Exception {... |
| 238 |
1
|
final File file = new File("testLoadFileFileStringBuffer.txt"); |
| 239 |
1
|
if (file.exists()) { |
| 240 |
0
|
assertTrue(file.delete()); |
| 241 |
|
} |
| 242 |
1
|
final Writer out = new FileWriter(file); |
| 243 |
1
|
final String expected = "We all live in a yellow submarine ..."; |
| 244 |
1
|
out.write(expected); |
| 245 |
1
|
out.close(); |
| 246 |
1
|
final StringBuffer buffer = new StringBuffer(); |
| 247 |
1
|
IoUtility.loadFile(file, buffer); |
| 248 |
1
|
assertEquals(expected, buffer.toString()); |
| 249 |
1
|
assertTrue(file.delete()); |
| 250 |
|
} |
| 251 |
|
|
| 252 |
|
|
| 253 |
|
@link |
| 254 |
|
|
| 255 |
|
@throws |
| 256 |
|
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
1
PASS
|
|
| 257 |
1
|
public void testLoadFileFileStringBufferString() throws Exception {... |
| 258 |
1
|
final File file = new File("testLoadFileFileStringBufferString.txt"); |
| 259 |
1
|
if (file.exists()) { |
| 260 |
0
|
assertTrue(file.delete()); |
| 261 |
|
} |
| 262 |
1
|
final String expected1 = "We all live in a yellow submarine ..."; |
| 263 |
1
|
final String encoding1 = "UTF-16"; |
| 264 |
1
|
assertEquals(expected1, loadFile(file, expected1, encoding1)); |
| 265 |
1
|
final String expected2 = "We all live in a yellow submarine\n" |
| 266 |
|
+ "Yellow submarine, yellow submarine\n" |
| 267 |
|
+ "We all live in a yellow submarine\n" |
| 268 |
|
+ "Yellow submarine, yellow submarine\n" |
| 269 |
|
+ "\n" |
| 270 |
|
+ "As we live a life of ease\n" |
| 271 |
|
+ "Everyone of us has all we need\n" |
| 272 |
|
+ "Sky of blue and sea of green\n" |
| 273 |
|
+ "In our yellow submarine "; |
| 274 |
1
|
final String encoding2 = "UnicodeBigUnmarked"; |
| 275 |
1
|
assertEquals(expected2, loadFile(file, expected2, encoding2)); |
| 276 |
1
|
final String encoding3 = "ASCII"; |
| 277 |
1
|
assertEquals(expected2, loadFile(file, expected2, encoding3)); |
| 278 |
1
|
assertTrue(file.delete()); |
| 279 |
|
} |
| 280 |
|
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 281 |
3
|
private String loadFile(final File file, final String expected, final String encoding)... |
| 282 |
|
throws FileNotFoundException, IOException, UnsupportedEncodingException { |
| 283 |
3
|
final OutputStream out = new FileOutputStream(file); |
| 284 |
3
|
try { |
| 285 |
3
|
out.write(expected.getBytes(encoding)); |
| 286 |
|
} finally { |
| 287 |
3
|
if (out != null) { |
| 288 |
3
|
out.close(); |
| 289 |
|
} |
| 290 |
|
} |
| 291 |
3
|
final StringBuffer buffer = new StringBuffer(); |
| 292 |
3
|
IoUtility.loadFile(file, buffer, encoding); |
| 293 |
3
|
return buffer.toString(); |
| 294 |
|
} |
| 295 |
|
|
| 296 |
|
|
| 297 |
|
@link |
| 298 |
|
|
| 299 |
|
@throws |
| 300 |
|
|
|
|
|
| 92.6% |
Uncovered Elements: 2 (27) |
Complexity: 6 |
Complexity Density: 0.35 |
1
PASS
|
|
| 301 |
1
|
public void testLoadFileBinary1() throws Exception {... |
| 302 |
1
|
final File file = new File("IoUtilityTestLoadBinary1.bin"); |
| 303 |
1
|
if (file.exists()) { |
| 304 |
0
|
assertTrue(file.delete()); |
| 305 |
|
} |
| 306 |
1
|
final OutputStream out = new FileOutputStream(file); |
| 307 |
1
|
try { |
| 308 |
257
|
for (int i = 0; i < 256; i++) { |
| 309 |
256
|
out.write(i); |
| 310 |
|
} |
| 311 |
257
|
for (int i = 0; i < 256; i++) { |
| 312 |
256
|
out.write(i); |
| 313 |
|
} |
| 314 |
|
} finally { |
| 315 |
1
|
out.close(); |
| 316 |
|
} |
| 317 |
1
|
final byte [] loaded = IoUtility.loadFileBinary(file); |
| 318 |
1
|
assertEquals(512, loaded.length); |
| 319 |
257
|
for (int i = 0; i < 256; i++) { |
| 320 |
256
|
assertEquals((byte) i, loaded[i]); |
| 321 |
|
} |
| 322 |
257
|
for (int i = 0; i < 256; i++) { |
| 323 |
256
|
assertEquals((byte) i, loaded[i]); |
| 324 |
|
} |
| 325 |
1
|
assertTrue(file.delete()); |
| 326 |
|
} |
| 327 |
|
|
| 328 |
|
|
| 329 |
|
@link |
| 330 |
|
|
| 331 |
|
@throws |
| 332 |
|
|
|
|
|
| 93.9% |
Uncovered Elements: 2 (33) |
Complexity: 8 |
Complexity Density: 0.42 |
1
PASS
|
|
| 333 |
1
|
public void testLoadFileBinary2() throws Exception {... |
| 334 |
1
|
final File file = new File("IoUtilityTestLoadBinary2.bin"); |
| 335 |
1
|
if (file.exists()) { |
| 336 |
0
|
assertTrue(file.delete()); |
| 337 |
|
} |
| 338 |
1
|
final OutputStream out = new FileOutputStream(file); |
| 339 |
1
|
try { |
| 340 |
513
|
for (int j = 0; j < 512; j++) { |
| 341 |
131584
|
for (int i = 0; i < 256; i++) { |
| 342 |
131072
|
out.write(i); |
| 343 |
|
} |
| 344 |
131584
|
for (int i = 0; i < 256; i++) { |
| 345 |
131072
|
out.write(255 - i); |
| 346 |
|
} |
| 347 |
|
} |
| 348 |
|
} finally { |
| 349 |
1
|
out.close(); |
| 350 |
|
} |
| 351 |
1
|
final byte [] loaded = IoUtility.loadFileBinary(file); |
| 352 |
1
|
assertEquals(512 * 2 * 256, loaded.length); |
| 353 |
513
|
for (int j = 0; j < 512; j++) { |
| 354 |
131584
|
for (int i = 0; i < 256; i++) { |
| 355 |
131072
|
assertEquals((byte) i, loaded[i + 512 * j]); |
| 356 |
|
} |
| 357 |
131584
|
for (int i = 0; i < 256; i++) { |
| 358 |
131072
|
assertEquals((byte) (255 - i), loaded[i + 256 + 512 * j]); |
| 359 |
|
} |
| 360 |
|
} |
| 361 |
1
|
assertTrue(file.delete()); |
| 362 |
|
} |
| 363 |
|
|
| 364 |
|
|
| 365 |
|
@link |
| 366 |
|
|
| 367 |
|
@throws |
| 368 |
|
|
|
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 5 |
Complexity Density: 0.31 |
1
PASS
|
|
| 369 |
1
|
public void testSaveFileBinary() throws Exception {... |
| 370 |
1
|
final File file = new File("IoUtilityTestSaveFileBinary.bin"); |
| 371 |
1
|
if (file.exists()) { |
| 372 |
0
|
assertTrue(file.delete()); |
| 373 |
|
} |
| 374 |
1
|
final byte[] data = new byte[512]; |
| 375 |
513
|
for (int i = 0; i < 512; i++) { |
| 376 |
512
|
data[i] = (byte) i; |
| 377 |
|
} |
| 378 |
1
|
IoUtility.saveFileBinary(file, data); |
| 379 |
1
|
final InputStream in = new FileInputStream(file); |
| 380 |
1
|
try { |
| 381 |
257
|
for (int i = 0; i < 256; i++) { |
| 382 |
256
|
assertEquals(i, in.read()); |
| 383 |
|
} |
| 384 |
257
|
for (int i = 0; i < 256; i++) { |
| 385 |
256
|
assertEquals(i, in.read()); |
| 386 |
|
} |
| 387 |
1
|
assertEquals(-1, in.read()); |
| 388 |
|
} finally { |
| 389 |
1
|
in.close(); |
| 390 |
|
} |
| 391 |
1
|
assertTrue(file.delete()); |
| 392 |
|
} |
| 393 |
|
|
| 394 |
|
|
| 395 |
|
@link |
| 396 |
|
|
| 397 |
|
@throws |
| 398 |
|
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
1
PASS
|
|
| 399 |
1
|
public void testLoadAndSaveFileBinary() throws Exception {... |
| 400 |
1
|
final File file = new File("testLoadAndSaveFileBinary.bin"); |
| 401 |
1
|
if (file.exists()) { |
| 402 |
0
|
assertTrue(file.delete()); |
| 403 |
|
} |
| 404 |
1
|
Random random = new Random(1001); |
| 405 |
1
|
final byte[] data = new byte[100000]; |
| 406 |
513
|
for (int i = 0; i < 512; i++) { |
| 407 |
512
|
data[i] = (byte) i; |
| 408 |
|
} |
| 409 |
99489
|
for (int i = 512; i < data.length; i++) { |
| 410 |
99488
|
data[i] = (byte) random.nextInt(); |
| 411 |
|
} |
| 412 |
1
|
IoUtility.saveFileBinary(file, data); |
| 413 |
1
|
assertTrue(EqualsUtility.equals(data, IoUtility.loadFileBinary(file))); |
| 414 |
1
|
assertTrue(file.delete()); |
| 415 |
|
} |
| 416 |
|
|
| 417 |
|
|
| 418 |
|
@link |
| 419 |
|
|
| 420 |
|
@throws |
| 421 |
|
|
|
|
|
| 88.1% |
Uncovered Elements: 5 (42) |
Complexity: 5 |
Complexity Density: 0.14 |
1
PASS
|
|
| 422 |
1
|
public void testCompareFileBinary() throws Exception {... |
| 423 |
1
|
final File file1 = new File("IoUtilityTestLoadBinary1.bin"); |
| 424 |
1
|
if (file1.exists()) { |
| 425 |
0
|
assertTrue(file1.delete()); |
| 426 |
|
} |
| 427 |
1
|
final File file2 = new File("IoUtilityTestLoadBinary2.bin"); |
| 428 |
1
|
if (file2.exists()) { |
| 429 |
0
|
assertTrue(file2.delete()); |
| 430 |
|
} |
| 431 |
1
|
assertFalse(IoUtility.compareFilesBinary(null, file1)); |
| 432 |
1
|
assertFalse(IoUtility.compareFilesBinary(file2, null)); |
| 433 |
1
|
assertTrue(IoUtility.compareFilesBinary(null, null)); |
| 434 |
1
|
try { |
| 435 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file2)); |
| 436 |
0
|
fail("FileNotFoundException expected"); |
| 437 |
|
} catch (FileNotFoundException e) { |
| 438 |
|
|
| 439 |
|
} |
| 440 |
1
|
Random random = new Random(1001); |
| 441 |
1
|
final byte[] data = new byte[1025]; |
| 442 |
1026
|
for (int i = 0; i < data.length; i++) { |
| 443 |
1025
|
data[i] = (byte) random.nextInt(); |
| 444 |
|
} |
| 445 |
1
|
IoUtility.saveFileBinary(file1, data); |
| 446 |
1
|
IoUtility.saveFileBinary(file2, data); |
| 447 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file2)); |
| 448 |
1
|
data[1000] += 1; |
| 449 |
1
|
IoUtility.saveFileBinary(file2, data); |
| 450 |
1
|
assertFalse(IoUtility.compareFilesBinary(file1, file2)); |
| 451 |
1
|
data[999] -= 1; |
| 452 |
1
|
IoUtility.saveFileBinary(file2, data); |
| 453 |
1
|
assertFalse(IoUtility.compareFilesBinary(file1, file2)); |
| 454 |
1
|
IoUtility.saveFileBinary(file2, new byte[] {}); |
| 455 |
1
|
assertEquals(0, file2.length()); |
| 456 |
1
|
assertFalse(IoUtility.compareFilesBinary(file1, file2)); |
| 457 |
1
|
assertFalse(IoUtility.compareFilesBinary(file2, file1)); |
| 458 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file1)); |
| 459 |
1
|
assertTrue(IoUtility.compareFilesBinary(file2, file2)); |
| 460 |
1
|
IoUtility.saveFileBinary(file2, new byte[] {'A', 'B', 'C'}); |
| 461 |
1
|
assertFalse(IoUtility.compareFilesBinary(file1, file2)); |
| 462 |
1
|
assertFalse(IoUtility.compareFilesBinary(file2, file1)); |
| 463 |
1
|
assertTrue(file1.delete()); |
| 464 |
1
|
assertTrue(file2.delete()); |
| 465 |
|
} |
| 466 |
|
|
| 467 |
|
|
| 468 |
|
@link |
| 469 |
|
|
| 470 |
|
@throws |
| 471 |
|
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
1
PASS
|
|
| 472 |
1
|
public void testLoadFileURLStringBuffer() throws Exception {... |
| 473 |
1
|
final File file = new File("testLoadFileURLStringBuffer.txt"); |
| 474 |
1
|
if (file.exists()) { |
| 475 |
0
|
assertTrue(file.delete()); |
| 476 |
|
} |
| 477 |
1
|
final Writer out = new FileWriter(file); |
| 478 |
1
|
final String expected = "We all live in a yellow submarine ..."; |
| 479 |
1
|
out.write(expected); |
| 480 |
1
|
out.close(); |
| 481 |
1
|
final StringBuffer buffer = new StringBuffer(); |
| 482 |
1
|
IoUtility.loadFile(file.toURL(), buffer); |
| 483 |
1
|
assertEquals(expected, buffer.toString()); |
| 484 |
1
|
assertTrue(file.delete()); |
| 485 |
|
} |
| 486 |
|
|
| 487 |
|
|
| 488 |
|
@link |
| 489 |
|
|
| 490 |
|
@throws |
| 491 |
|
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 2 |
Complexity Density: 0.13 |
1
PASS
|
|
| 492 |
1
|
public void testLoadFileURLStringBufferString() throws Exception {... |
| 493 |
1
|
final File file = new File("testLoadFileURLStringBufferString.txt"); |
| 494 |
1
|
if (file.exists()) { |
| 495 |
0
|
assertTrue(file.delete()); |
| 496 |
|
} |
| 497 |
1
|
final Writer out = new FileWriter(file); |
| 498 |
1
|
final String expected = "We all live in a yellow submarine ...\n"; |
| 499 |
1
|
final String encoding = "UTF-8"; |
| 500 |
1
|
out.write(expected); |
| 501 |
1
|
out.close(); |
| 502 |
1
|
final StringBuffer buffer = new StringBuffer(); |
| 503 |
1
|
IoUtility.loadFile(file.toURL(), buffer, encoding); |
| 504 |
1
|
assertEquals(expected, buffer.toString()); |
| 505 |
1
|
IoUtility.saveFileBinary(file, StringUtility.hex2byte( |
| 506 |
|
"FF FE 49 00 20 00 61 00 6D 00 20 00 64 00 72 00" |
| 507 |
|
+ "65 00 61 00 6D 00 69 00 6E 00 67 00 20 00 6F 00" |
| 508 |
|
+ "66 00 20 00 61 00 20 00 77 00 68 00 69 00 74 00" |
| 509 |
|
+ "65 00 20 00 63 00 68 00 72 00 69 00 73 00 74 00" |
| 510 |
|
+ "6D 00 61 00 73 00 73 00 2E 00 2E 00 2E 00")); |
| 511 |
1
|
IoUtility.loadFile(file.toURL(), buffer, "UTF16"); |
| 512 |
1
|
assertEquals(expected + "I am dreaming of a white christmass...", buffer.toString()); |
| 513 |
1
|
assertTrue(file.delete()); |
| 514 |
|
} |
| 515 |
|
|
| 516 |
|
|
| 517 |
|
@link |
| 518 |
|
|
| 519 |
|
@throws |
| 520 |
|
|
|
|
|
| 73.3% |
Uncovered Elements: 4 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
1
PASS
|
|
| 521 |
1
|
public void testSaveFileURLFile() throws Exception {... |
| 522 |
1
|
final File file1 = new File("testSaveFileURLFile1.txt"); |
| 523 |
1
|
final File file2 = new File("testSaveFileURLFile2.txt"); |
| 524 |
1
|
if (file1.exists()) { |
| 525 |
0
|
assertTrue(file1.delete()); |
| 526 |
|
} |
| 527 |
1
|
if (file2.exists()) { |
| 528 |
0
|
assertTrue(file2.delete()); |
| 529 |
|
} |
| 530 |
1
|
IoUtility.saveFileBinary(file1, StringUtility.hex2byte( |
| 531 |
|
"FF FE 49 00 20 00 61 00 6D 00 20 00 64 00 72 00" |
| 532 |
|
+ "65 00 61 00 6D 00 69 00 6E 00 67 00 20 00 6F 00" |
| 533 |
|
+ "66 00 20 00 61 00 20 00 77 00 68 00 69 00 74 00" |
| 534 |
|
+ "65 00 20 00 63 00 68 00 72 00 69 00 73 00 74 00" |
| 535 |
|
+ "6D 00 61 00 73 00 73 00 2E 00 2E 00 2E 00")); |
| 536 |
1
|
IoUtility.saveFile(file1.toURL(), file2); |
| 537 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file2)); |
| 538 |
1
|
assertTrue(file1.delete()); |
| 539 |
1
|
assertTrue(file2.delete()); |
| 540 |
|
} |
| 541 |
|
|
| 542 |
|
|
| 543 |
|
@link |
| 544 |
|
|
| 545 |
|
@throws |
| 546 |
|
|
|
|
|
| 77.3% |
Uncovered Elements: 5 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
1
PASS
|
|
| 547 |
1
|
public void testSaveFileInputStreamFile() throws Exception {... |
| 548 |
1
|
final File file1 = new File("testSaveFileInputStreamFile1.txt"); |
| 549 |
1
|
final File file2 = new File("testSaveFileInputStreamFile2.txt"); |
| 550 |
1
|
InputStream in = null; |
| 551 |
1
|
try { |
| 552 |
1
|
if (file1.exists()) { |
| 553 |
0
|
assertTrue(file1.delete()); |
| 554 |
|
} |
| 555 |
1
|
if (file2.exists()) { |
| 556 |
0
|
assertTrue(file2.delete()); |
| 557 |
|
} |
| 558 |
1
|
IoUtility.saveFileBinary(file1, StringUtility.hex2byte( |
| 559 |
|
"FF FE 49 00 20 00 61 00 6D 00 20 00 64 00 72 00" |
| 560 |
|
+ "65 00 61 00 6D 00 69 00 6E 00 67 00 20 00 6F 00" |
| 561 |
|
+ "66 00 20 00 61 00 20 00 77 00 68 00 69 00 74 00" |
| 562 |
|
+ "65 00 20 00 63 00 68 00 72 00 69 00 73 00 74 00" |
| 563 |
|
+ "6D 00 61 00 73 00 73 00 2E 00 2E 00 2E 00")); |
| 564 |
1
|
in = new FileInputStream(file1); |
| 565 |
1
|
IoUtility.saveFile(in, file2); |
| 566 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file2)); |
| 567 |
|
} finally { |
| 568 |
1
|
if (in != null) { |
| 569 |
1
|
in.close(); |
| 570 |
|
} |
| 571 |
|
} |
| 572 |
1
|
assertTrue(file1.delete()); |
| 573 |
1
|
assertTrue(file2.delete()); |
| 574 |
|
} |
| 575 |
|
|
| 576 |
|
|
| 577 |
|
@link |
| 578 |
|
|
| 579 |
|
@throws |
| 580 |
|
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
1
PASS
|
|
| 581 |
1
|
public void testStringToReader() throws Exception {... |
| 582 |
1
|
final String expected = "We all live in a yellow submarine\n" |
| 583 |
|
+ "Yellow submarine, yellow submarine\n" |
| 584 |
|
+ "We all live in a yellow submarine\n" |
| 585 |
|
+ "Yellow submarine, yellow submarine\n" |
| 586 |
|
+ "\n" |
| 587 |
|
+ "As we live a life of ease\n" |
| 588 |
|
+ "Everyone of us has all we need\n" |
| 589 |
|
+ "Sky of blue and sea of green\n" |
| 590 |
|
+ "In our yellow submarine "; |
| 591 |
1
|
final Reader reader = IoUtility.stringToReader(expected); |
| 592 |
1
|
final StringBuffer buffer = new StringBuffer(); |
| 593 |
1
|
int c; |
| 594 |
?
|
while (0 <= (c = (reader.read()))) { |
| 595 |
249
|
buffer.append((char) c); |
| 596 |
|
} |
| 597 |
1
|
assertEquals(expected, buffer.toString()); |
| 598 |
|
} |
| 599 |
|
|
| 600 |
|
|
| 601 |
|
@link |
| 602 |
|
|
| 603 |
|
@throws |
| 604 |
|
|
|
|
|
| 77.3% |
Uncovered Elements: 5 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
1
PASS
|
|
| 605 |
1
|
public void testSaveFileFileString() throws Exception {... |
| 606 |
1
|
final File file1 = new File("testSaveFileFileString1.txt"); |
| 607 |
1
|
final File file2 = new File("testSaveFileFileString2.txt"); |
| 608 |
1
|
InputStream in = null; |
| 609 |
1
|
try { |
| 610 |
1
|
if (file1.exists()) { |
| 611 |
0
|
assertTrue(file1.delete()); |
| 612 |
|
} |
| 613 |
1
|
if (file2.exists()) { |
| 614 |
0
|
assertTrue(file2.delete()); |
| 615 |
|
} |
| 616 |
1
|
IoUtility.saveFile(file1, StringUtility.hex2String( |
| 617 |
|
"FF FE 49 00 20 00 61 00 6D 00 20 00 64 00 72 00" |
| 618 |
|
+ "65 00 61 00 6D 00 69 00 6E 00 67 00 20 00 6F 00" |
| 619 |
|
+ "66 00 20 00 61 00 20 00 77 00 68 00 69 00 74 00" |
| 620 |
|
+ "65 00 20 00 63 00 68 00 72 00 69 00 73 00 74 00" |
| 621 |
|
+ "6D 00 61 00 73 00 73 00 2E 00 2E 00 2E 00")); |
| 622 |
1
|
in = new FileInputStream(file1); |
| 623 |
1
|
IoUtility.saveFile(in, file2); |
| 624 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file2)); |
| 625 |
|
} finally { |
| 626 |
1
|
if (in != null) { |
| 627 |
1
|
in.close(); |
| 628 |
|
} |
| 629 |
|
} |
| 630 |
1
|
assertTrue(file1.delete()); |
| 631 |
1
|
assertTrue(file2.delete()); |
| 632 |
|
} |
| 633 |
|
|
| 634 |
|
|
| 635 |
|
@link |
| 636 |
|
|
| 637 |
|
@throws |
| 638 |
|
|
|
|
|
| 78.3% |
Uncovered Elements: 5 (23) |
Complexity: 4 |
Complexity Density: 0.24 |
1
PASS
|
|
| 639 |
1
|
public void testSaveFileFileStringBuffer() throws Exception {... |
| 640 |
1
|
final File file1 = new File("testSaveFileFileStringBuffer1.txt"); |
| 641 |
1
|
final File file2 = new File("testSaveFileFileStringBuffer2.txt"); |
| 642 |
1
|
InputStream in = null; |
| 643 |
1
|
try { |
| 644 |
1
|
if (file1.exists()) { |
| 645 |
0
|
assertTrue(file1.delete()); |
| 646 |
|
} |
| 647 |
1
|
if (file2.exists()) { |
| 648 |
0
|
assertTrue(file2.delete()); |
| 649 |
|
} |
| 650 |
1
|
final StringBuffer buffer = new StringBuffer(StringUtility.hex2String( |
| 651 |
|
"FF FE 49 00 20 00 61 00 6D 00 20 00 64 00 72 00" |
| 652 |
|
+ "65 00 61 00 6D 00 69 00 6E 00 67 00 20 00 6F 00" |
| 653 |
|
+ "66 00 20 00 61 00 20 00 77 00 68 00 69 00 74 00" |
| 654 |
|
+ "65 00 20 00 63 00 68 00 72 00 69 00 73 00 74 00" |
| 655 |
|
+ "6D 00 61 00 73 00 73 00 2E 00 2E 00 2E 00")); |
| 656 |
1
|
IoUtility.saveFile(file1, buffer); |
| 657 |
1
|
in = new FileInputStream(file1); |
| 658 |
1
|
IoUtility.saveFile(in, file2); |
| 659 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file2)); |
| 660 |
|
} finally { |
| 661 |
1
|
if (in != null) { |
| 662 |
1
|
in.close(); |
| 663 |
|
} |
| 664 |
|
} |
| 665 |
1
|
assertTrue(file1.delete()); |
| 666 |
1
|
assertTrue(file2.delete()); |
| 667 |
|
} |
| 668 |
|
|
| 669 |
|
|
| 670 |
|
@link |
| 671 |
|
|
| 672 |
|
@throws |
| 673 |
|
|
|
|
|
| 77.4% |
Uncovered Elements: 7 (31) |
Complexity: 5 |
Complexity Density: 0.22 |
1
PASS
|
|
| 674 |
1
|
public void testSaveFileFileStringString() throws Exception {... |
| 675 |
1
|
final File file1 = new File("testSaveFileFileStringString1.txt"); |
| 676 |
1
|
final File file2 = new File("testSaveFileFileStringString2.txt"); |
| 677 |
1
|
final File file3 = new File("testSaveFileFileStringString3.txt"); |
| 678 |
1
|
InputStream in = null; |
| 679 |
1
|
try { |
| 680 |
1
|
if (file1.exists()) { |
| 681 |
0
|
assertTrue(file1.delete()); |
| 682 |
|
} |
| 683 |
1
|
if (file2.exists()) { |
| 684 |
0
|
assertTrue(file2.delete()); |
| 685 |
|
} |
| 686 |
1
|
if (file3.exists()) { |
| 687 |
0
|
assertTrue(file3.delete()); |
| 688 |
|
} |
| 689 |
1
|
final String data = StringUtility.hex2String( |
| 690 |
|
"FF FE 49 00 20 00 61 00 6D 00 20 00 64 00 72 00" |
| 691 |
|
+ "65 00 61 00 6D 00 69 00 6E 00 67 00 20 00 6F 00" |
| 692 |
|
+ "66 00 20 00 61 00 20 00 77 00 68 00 69 00 74 00" |
| 693 |
|
+ "65 00 20 00 63 00 68 00 72 00 69 00 73 00 74 00" |
| 694 |
|
+ "6D 00 61 00 73 00 73 00 2E 00 2E 00 2E 00"); |
| 695 |
1
|
IoUtility.saveFile(file1, data, "ISO-8859-1"); |
| 696 |
1
|
in = new FileInputStream(file1); |
| 697 |
1
|
IoUtility.saveFile(in, file2); |
| 698 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file2)); |
| 699 |
1
|
IoUtility.saveFile(file3, "I am dreaming of a white christmass...", "UTF-16"); |
| 700 |
1
|
assertEquals("I am dreaming of a white christmass...", IoUtility.loadFile( |
| 701 |
|
file3.toString(), "UTF-16")); |
| 702 |
|
} finally { |
| 703 |
1
|
if (in != null) { |
| 704 |
1
|
in.close(); |
| 705 |
|
} |
| 706 |
|
} |
| 707 |
1
|
assertTrue(file1.delete()); |
| 708 |
1
|
assertTrue(file2.delete()); |
| 709 |
1
|
assertTrue(file3.delete()); |
| 710 |
|
} |
| 711 |
|
|
| 712 |
|
|
| 713 |
|
@link |
| 714 |
|
|
| 715 |
|
@throws |
| 716 |
|
|
|
|
|
| 78.3% |
Uncovered Elements: 5 (23) |
Complexity: 4 |
Complexity Density: 0.24 |
1
PASS
|
|
| 717 |
1
|
public void testSaveFileStringString() throws Exception {... |
| 718 |
1
|
final File file1 = new File("testSaveFileStringString1.txt"); |
| 719 |
1
|
final File file2 = new File("testSaveFileStringString2.txt"); |
| 720 |
1
|
InputStream in = null; |
| 721 |
1
|
try { |
| 722 |
1
|
if (file1.exists()) { |
| 723 |
0
|
assertTrue(file1.delete()); |
| 724 |
|
} |
| 725 |
1
|
if (file2.exists()) { |
| 726 |
0
|
assertTrue(file2.delete()); |
| 727 |
|
} |
| 728 |
1
|
final StringBuffer buffer = new StringBuffer(StringUtility.hex2String( |
| 729 |
|
"FF FE 49 00 20 00 61 00 6D 00 20 00 64 00 72 00" |
| 730 |
|
+ "65 00 61 00 6D 00 69 00 6E 00 67 00 20 00 6F 00" |
| 731 |
|
+ "66 00 20 00 61 00 20 00 77 00 68 00 69 00 74 00" |
| 732 |
|
+ "65 00 20 00 63 00 68 00 72 00 69 00 73 00 74 00" |
| 733 |
|
+ "6D 00 61 00 73 00 73 00 2E 00 2E 00 2E 00")); |
| 734 |
1
|
IoUtility.saveFile(file1.toString(), buffer.toString()); |
| 735 |
1
|
in = new FileInputStream(file1); |
| 736 |
1
|
IoUtility.saveFile(in, file2); |
| 737 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file2)); |
| 738 |
|
} finally { |
| 739 |
1
|
if (in != null) { |
| 740 |
1
|
in.close(); |
| 741 |
|
} |
| 742 |
|
} |
| 743 |
1
|
assertTrue(file1.delete()); |
| 744 |
1
|
assertTrue(file2.delete()); |
| 745 |
|
} |
| 746 |
|
|
| 747 |
|
|
| 748 |
|
@link |
| 749 |
|
|
| 750 |
|
@throws |
| 751 |
|
|
|
|
|
| 78.3% |
Uncovered Elements: 5 (23) |
Complexity: 4 |
Complexity Density: 0.24 |
1
PASS
|
|
| 752 |
1
|
public void testSaveFileStringStringBuffer() throws Exception {... |
| 753 |
1
|
final File file1 = new File("testSaveFileStringString1.txt"); |
| 754 |
1
|
final File file2 = new File("testSaveFileStringString2.txt"); |
| 755 |
1
|
InputStream in = null; |
| 756 |
1
|
try { |
| 757 |
1
|
if (file1.exists()) { |
| 758 |
0
|
assertTrue(file1.delete()); |
| 759 |
|
} |
| 760 |
1
|
if (file2.exists()) { |
| 761 |
0
|
assertTrue(file2.delete()); |
| 762 |
|
} |
| 763 |
1
|
final StringBuffer buffer = new StringBuffer(StringUtility.hex2String( |
| 764 |
|
"FF FE 49 00 20 00 61 00 6D 00 20 00 64 00 72 00" |
| 765 |
|
+ "65 00 61 00 6D 00 69 00 6E 00 67 00 20 00 6F 00" |
| 766 |
|
+ "66 00 20 00 61 00 20 00 77 00 68 00 69 00 74 00" |
| 767 |
|
+ "65 00 20 00 63 00 68 00 72 00 69 00 73 00 74 00" |
| 768 |
|
+ "6D 00 61 00 73 00 73 00 2E 00 2E 00 2E 00")); |
| 769 |
1
|
IoUtility.saveFile(file1.toString(), buffer); |
| 770 |
1
|
in = new FileInputStream(file1); |
| 771 |
1
|
IoUtility.saveFile(in, file2); |
| 772 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file2)); |
| 773 |
|
} finally { |
| 774 |
1
|
if (in != null) { |
| 775 |
1
|
in.close(); |
| 776 |
|
} |
| 777 |
|
} |
| 778 |
1
|
assertTrue(file1.delete()); |
| 779 |
1
|
assertTrue(file2.delete()); |
| 780 |
|
} |
| 781 |
|
|
| 782 |
|
|
| 783 |
|
@link |
| 784 |
|
|
| 785 |
|
@throws |
| 786 |
|
|
|
|
|
| 79.4% |
Uncovered Elements: 7 (34) |
Complexity: 5 |
Complexity Density: 0.19 |
1
PASS
|
|
| 787 |
1
|
public void testSaveFileFileStringBufferString() throws Exception {... |
| 788 |
1
|
final File file1 = new File("testSaveFileFileStringBufferString1.txt"); |
| 789 |
1
|
final File file2 = new File("testSaveFileFileStringBufferString2.txt"); |
| 790 |
1
|
final File file3 = new File("testSaveFileFileStringBufferString3.txt"); |
| 791 |
1
|
InputStream in = null; |
| 792 |
1
|
try { |
| 793 |
1
|
if (file1.exists()) { |
| 794 |
0
|
assertTrue(file1.delete()); |
| 795 |
|
} |
| 796 |
1
|
if (file2.exists()) { |
| 797 |
0
|
assertTrue(file2.delete()); |
| 798 |
|
} |
| 799 |
1
|
if (file3.exists()) { |
| 800 |
0
|
assertTrue(file3.delete()); |
| 801 |
|
} |
| 802 |
1
|
final String data = StringUtility.hex2String( |
| 803 |
|
"FF FE 49 00 20 00 61 00 6D 00 20 00 64 00 72 00" |
| 804 |
|
+ "65 00 61 00 6D 00 69 00 6E 00 67 00 20 00 6F 00" |
| 805 |
|
+ "66 00 20 00 61 00 20 00 77 00 68 00 69 00 74 00" |
| 806 |
|
+ "65 00 20 00 63 00 68 00 72 00 69 00 73 00 74 00" |
| 807 |
|
+ "6D 00 61 00 73 00 73 00 2E 00 2E 00 2E 00"); |
| 808 |
1
|
final StringBuffer buffer = new StringBuffer(data); |
| 809 |
1
|
IoUtility.saveFile(file1, buffer, "ISO-8859-1"); |
| 810 |
1
|
in = new FileInputStream(file1); |
| 811 |
1
|
IoUtility.saveFile(in, file2); |
| 812 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file2)); |
| 813 |
1
|
buffer.setLength(0); |
| 814 |
1
|
buffer.append("I am dreaming of a white christmass..."); |
| 815 |
1
|
IoUtility.saveFile(file3, buffer, "UTF-16"); |
| 816 |
1
|
assertEquals("I am dreaming of a white christmass...", IoUtility.loadFile( |
| 817 |
|
file3.toString(), "UTF-16")); |
| 818 |
|
} finally { |
| 819 |
1
|
if (in != null) { |
| 820 |
1
|
in.close(); |
| 821 |
|
} |
| 822 |
|
} |
| 823 |
1
|
assertTrue(file1.delete()); |
| 824 |
1
|
assertTrue(file2.delete()); |
| 825 |
1
|
assertTrue(file3.delete()); |
| 826 |
|
} |
| 827 |
|
|
| 828 |
|
|
| 829 |
|
@link |
| 830 |
|
|
| 831 |
|
@throws |
| 832 |
|
|
|
|
|
| 81.8% |
Uncovered Elements: 4 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
1
PASS
|
|
| 833 |
1
|
public void testCopyFile() throws Exception {... |
| 834 |
1
|
final File file1 = new File("IoUtilityTestCopyFile1.bin"); |
| 835 |
1
|
if (file1.exists()) { |
| 836 |
0
|
assertTrue(file1.delete()); |
| 837 |
|
} |
| 838 |
1
|
final File file2 = new File("IoUtilityTestCopyFile2.bin"); |
| 839 |
1
|
if (file2.exists()) { |
| 840 |
0
|
assertTrue(file2.delete()); |
| 841 |
|
} |
| 842 |
1
|
Random random = new Random(1007); |
| 843 |
1
|
final byte[] data = new byte[1025]; |
| 844 |
1026
|
for (int i = 0; i < data.length; i++) { |
| 845 |
1025
|
data[i] = (byte) random.nextInt(); |
| 846 |
|
} |
| 847 |
1
|
IoUtility.saveFileBinary(file1, data); |
| 848 |
1
|
IoUtility.copyFile(file1, file1); |
| 849 |
1
|
IoUtility.copyFile(file1, file2); |
| 850 |
1
|
assertTrue(IoUtility.compareFilesBinary(file1, file2)); |
| 851 |
1
|
file1.delete(); |
| 852 |
1
|
file2.delete(); |
| 853 |
|
} |
| 854 |
|
|
| 855 |
|
|
| 856 |
|
|
| 857 |
|
@link |
| 858 |
|
|
| 859 |
|
@throws |
| 860 |
|
|
|
|
|
| 83.7% |
Uncovered Elements: 7 (43) |
Complexity: 7 |
Complexity Density: 0.19 |
1
PASS
|
|
| 861 |
1
|
public void testCompareTextFiles1() throws Exception {... |
| 862 |
1
|
final File file1 = new File("testCompareTextFiles1.txt"); |
| 863 |
1
|
if (file1.exists()) { |
| 864 |
0
|
assertTrue(file1.delete()); |
| 865 |
|
} |
| 866 |
1
|
final File file2 = new File("testCompareTextFiles2.txt"); |
| 867 |
1
|
if (file2.exists()) { |
| 868 |
0
|
assertTrue(file2.delete()); |
| 869 |
|
} |
| 870 |
1
|
assertFalse(IoUtility.compareTextFiles(null, file1, "ISO-8859-1")); |
| 871 |
1
|
assertFalse(IoUtility.compareTextFiles(file2, null, "ISO-8859-1")); |
| 872 |
1
|
try { |
| 873 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 874 |
0
|
fail("FileNotFoundException expected"); |
| 875 |
|
} catch (FileNotFoundException e) { |
| 876 |
|
|
| 877 |
|
} |
| 878 |
1
|
Random random = new Random(1001); |
| 879 |
1
|
final byte[] data = new byte[1025]; |
| 880 |
1026
|
for (int i = 0; i < data.length; i++) { |
| 881 |
1025
|
data[i] = (byte) random.nextInt(); |
| 882 |
|
} |
| 883 |
1
|
IoUtility.saveFileBinary(file1, data); |
| 884 |
1
|
IoUtility.saveFileBinary(file2, data); |
| 885 |
1
|
try { |
| 886 |
1
|
IoUtility.compareTextFiles(file1, file2, "iso"); |
| 887 |
0
|
fail("UnsupportedEncodingException expected"); |
| 888 |
|
} catch (UnsupportedEncodingException e) { |
| 889 |
|
|
| 890 |
|
} |
| 891 |
1
|
try { |
| 892 |
1
|
IoUtility.compareTextFiles(file1, file2, null); |
| 893 |
0
|
fail("NullPointerException expected"); |
| 894 |
|
} catch (NullPointerException e) { |
| 895 |
|
|
| 896 |
|
} |
| 897 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 898 |
1
|
data[1000] += 1; |
| 899 |
1
|
IoUtility.saveFileBinary(file2, data); |
| 900 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 901 |
1
|
data[999] -= 1; |
| 902 |
1
|
IoUtility.saveFileBinary(file2, data); |
| 903 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 904 |
1
|
IoUtility.saveFileBinary(file2, new byte[] {}); |
| 905 |
1
|
assertEquals(0, file2.length()); |
| 906 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 907 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file1, "ISO-8859-1")); |
| 908 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file2, "ISO-8859-1")); |
| 909 |
1
|
assertTrue(file1.delete()); |
| 910 |
1
|
assertTrue(file2.delete()); |
| 911 |
|
} |
| 912 |
|
|
| 913 |
|
|
| 914 |
|
@link |
| 915 |
|
|
| 916 |
|
@throws |
| 917 |
|
|
|
|
|
| 95.2% |
Uncovered Elements: 5 (104) |
Complexity: 4 |
Complexity Density: 0.04 |
1
PASS
|
|
| 918 |
1
|
public void testCompareTextFiles2() throws Exception {... |
| 919 |
1
|
final String text = "When she goes, shes gone.@" + "If she stays, she stays here.@" |
| 920 |
|
+ "The girl does what she wants to do.@" + "She knows what she wants to do.@" |
| 921 |
|
+ "And I know Im fakin it,@" + "Im not really makin it.@" + "@" |
| 922 |
|
+ "Im such a dubious soul,@" + "And a walk in the garden@" + "Wears me down.@" |
| 923 |
|
+ "Tangled in the fallen vines,@" + "Pickin up the punch lines,@" |
| 924 |
|
+ "Ive just been fakin it,@" + "Not really makin it.@" + "@" + "Is there any danger?@" |
| 925 |
|
+ "No, no, not really.@" + "Just lean on me.@" + "Takin time to treat@" |
| 926 |
|
+ "Your friendly neighbors honestly.@" + "Ive just been fakin it,@" |
| 927 |
|
+ "Im not really makin it.@" + "This feeling of fakin it--@" |
| 928 |
|
+ "I still havent shaken it.@" + "@" + "Prior to this lifetime@" |
| 929 |
|
+ "I surely was a tailor.@" + "(good morning, mr. leitch.@" |
| 930 |
|
+ "Have you had a busy day? )@" + "I own the tailors face and hands.@" |
| 931 |
|
+ "I am the tailors face and hands and@" + "I know Im fakin it,@" |
| 932 |
|
+ "Im not really makin it.@" + "This feeling of fakin it--@" |
| 933 |
|
+ "I still havent shaken it."; |
| 934 |
1
|
final File file1 = new File("testCompareTextFiles1.txt"); |
| 935 |
1
|
if (file1.exists()) { |
| 936 |
0
|
assertTrue(file1.delete()); |
| 937 |
|
} |
| 938 |
1
|
final File file2 = new File("testCompareTextFiles2.txt"); |
| 939 |
1
|
if (file2.exists()) { |
| 940 |
0
|
assertTrue(file2.delete()); |
| 941 |
|
} |
| 942 |
1
|
IoUtility.saveFile(file1, "Line1", "ISO-8859-1"); |
| 943 |
1
|
IoUtility.saveFile(file2, "Line1", "ISO-8859-1"); |
| 944 |
|
|
| 945 |
1
|
assertFalse(IoUtility.compareTextFiles(null, file1, "ISO-8859-1")); |
| 946 |
1
|
assertFalse(IoUtility.compareTextFiles(file2, null, "ISO-8859-1")); |
| 947 |
1
|
assertTrue(IoUtility.compareTextFiles(null, null, "ISO-8859-1")); |
| 948 |
1
|
try { |
| 949 |
1
|
IoUtility.compareTextFiles(file1, file2, "iso"); |
| 950 |
0
|
fail("UnsupportedEncodingException expected"); |
| 951 |
|
} catch (UnsupportedEncodingException e) { |
| 952 |
|
|
| 953 |
|
} |
| 954 |
1
|
IoUtility.saveFile(file2, "line1", "ISO-8859-1"); |
| 955 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 956 |
1
|
assertFalse(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 957 |
|
|
| 958 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text, "@", "\n"), "ISO-8859-1"); |
| 959 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text, "@", "\n"), "ISO-8859-1"); |
| 960 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 961 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 962 |
|
|
| 963 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text, "@", "\015\012"), "ISO-8859-1"); |
| 964 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text, "@", "\015\012"), "ISO-8859-1"); |
| 965 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 966 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 967 |
|
|
| 968 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text, "@", "\012"), "ISO-8859-1"); |
| 969 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text, "@", "\015\012"), "ISO-8859-1"); |
| 970 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 971 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 972 |
|
|
| 973 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text + "@", "@", "\012"), "ISO-8859-1"); |
| 974 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text, "@", "\015\012"), "ISO-8859-1"); |
| 975 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 976 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 977 |
|
|
| 978 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text, "@", "\012"), "ISO-8859-1"); |
| 979 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text + "@", "@", "\015\012"), "ISO-8859-1"); |
| 980 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 981 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 982 |
|
|
| 983 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text + "@", "@", "\012"), "ISO-8859-1"); |
| 984 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text + "@", "@", "\015\012"), "ISO-8859-1"); |
| 985 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 986 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 987 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "UTF8")); |
| 988 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "UTF8")); |
| 989 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "UTF-16")); |
| 990 |
1
|
assertFalse(IoUtility.compareTextFiles(file2, file1, "UTF-16")); |
| 991 |
|
|
| 992 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text, "@", "\012"), "ISO-8859-1"); |
| 993 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text, "@", "\012"), "UTF8"); |
| 994 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 995 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 996 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "UTF8")); |
| 997 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "UTF8")); |
| 998 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "UTF-16")); |
| 999 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "UTF-16")); |
| 1000 |
|
|
| 1001 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text, "@", "\012"), "UTF16"); |
| 1002 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text, "@", "\012"), "UTF8"); |
| 1003 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "UTF-16")); |
| 1004 |
1
|
assertFalse(IoUtility.compareTextFiles(file2, file1, "UTF8")); |
| 1005 |
|
|
| 1006 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text, "@", "\012"), "UTF-16"); |
| 1007 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text, "@", "\012"), "UTF-16"); |
| 1008 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 1009 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 1010 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "UTF8")); |
| 1011 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "UTF8")); |
| 1012 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "UTF-16")); |
| 1013 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "UTF-16")); |
| 1014 |
|
|
| 1015 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text, "@", "\012"), "UTF-16"); |
| 1016 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text, "@", "\012\015"), "UTF-16"); |
| 1017 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 1018 |
1
|
assertFalse(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 1019 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "UTF8")); |
| 1020 |
1
|
assertFalse(IoUtility.compareTextFiles(file2, file1, "UTF8")); |
| 1021 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "UTF16")); |
| 1022 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "UTF16")); |
| 1023 |
|
|
| 1024 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text, "@", "\012"), "UTF-16"); |
| 1025 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text, "@", "\015\012"), "UTF-16"); |
| 1026 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 1027 |
1
|
assertFalse(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 1028 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "UTF8")); |
| 1029 |
1
|
assertFalse(IoUtility.compareTextFiles(file2, file1, "UTF8")); |
| 1030 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "UTF-16")); |
| 1031 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "UTF-16")); |
| 1032 |
|
|
| 1033 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text, "@", "\012"), "ISO-8859-1"); |
| 1034 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text, "@", "\015"), "ISO-8859-1"); |
| 1035 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 1036 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 1037 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "UTF8")); |
| 1038 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "UTF8")); |
| 1039 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "UTF-16")); |
| 1040 |
1
|
assertFalse(IoUtility.compareTextFiles(file2, file1, "UTF-16")); |
| 1041 |
|
|
| 1042 |
1
|
IoUtility.saveFile(file1, StringUtility.replace(text, "@", "\015\012"), "ISO-8859-1"); |
| 1043 |
1
|
IoUtility.saveFile(file2, StringUtility.replace(text, "@", "" + (char) 0x2029), |
| 1044 |
|
"ISO-8859-1"); |
| 1045 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "ISO-8859-1")); |
| 1046 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "ISO-8859-1")); |
| 1047 |
1
|
assertTrue(IoUtility.compareTextFiles(file1, file2, "UTF8")); |
| 1048 |
1
|
assertTrue(IoUtility.compareTextFiles(file2, file1, "UTF8")); |
| 1049 |
1
|
assertFalse(IoUtility.compareTextFiles(file1, file2, "UTF-16")); |
| 1050 |
1
|
assertFalse(IoUtility.compareTextFiles(file2, file1, "UTF-16")); |
| 1051 |
|
|
| 1052 |
1
|
assertTrue(file1.delete()); |
| 1053 |
1
|
assertTrue(file2.delete()); |
| 1054 |
|
} |
| 1055 |
|
|
| 1056 |
|
|
| 1057 |
|
@link |
| 1058 |
|
|
| 1059 |
|
@throws |
| 1060 |
|
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
1
PASS
|
|
| 1061 |
1
|
public void testDeleteDirFileBoolean() throws Exception {... |
| 1062 |
1
|
final File dir1 = new File("testDeleteDirFileBoolean_directory"); |
| 1063 |
1
|
if (dir1.exists()) { |
| 1064 |
0
|
assertTrue(IoUtility.deleteDir(dir1, true)); |
| 1065 |
|
} |
| 1066 |
1
|
final File dir2 = new File(dir1, "testDeleteDirFileBoolean_directory2"); |
| 1067 |
1
|
final File file1 = new File(dir1, "testDeleteDirFileBoolean1.txt"); |
| 1068 |
1
|
final File file2 = new File(dir1, "testDeleteDirFileBoolean2.txt"); |
| 1069 |
1
|
final File file3 = new File(dir2, "testDeleteDirFileBoolean3.txt"); |
| 1070 |
1
|
assertTrue(dir2.mkdirs()); |
| 1071 |
|
|
| 1072 |
1
|
IoUtility.saveFile(file1, "File 1", "ISO-8859-1"); |
| 1073 |
1
|
IoUtility.saveFile(file2, "File 2", "ISO-8859-1"); |
| 1074 |
1
|
IoUtility.saveFile(file3, "File 3", "ISO-8859-1"); |
| 1075 |
1
|
assertTrue(IoUtility.deleteDir(dir1, true)); |
| 1076 |
1
|
assertTrue(!dir1.exists()); |
| 1077 |
|
} |
| 1078 |
|
|
| 1079 |
|
|
| 1080 |
|
@link |
| 1081 |
|
|
| 1082 |
|
@throws |
| 1083 |
|
|
|
|
|
| 89.5% |
Uncovered Elements: 2 (19) |
Complexity: 2 |
Complexity Density: 0.12 |
1
PASS
|
|
| 1084 |
1
|
public void testDeleteDirFileFileFilter() throws Exception {... |
| 1085 |
1
|
final File dir1 = new File("testDeleteDirFileFileFilter_directory"); |
| 1086 |
1
|
if (dir1.exists()) { |
| 1087 |
0
|
assertTrue(IoUtility.deleteDir(dir1, true)); |
| 1088 |
|
} |
| 1089 |
1
|
final File dir2 = new File(dir1, "testDeleteDirFileFileFilter_directory2"); |
| 1090 |
1
|
final File file1 = new File(dir1, "testDeleteDirFileFileFilter1.txt"); |
| 1091 |
1
|
final File file2 = new File(dir1, "testDeleteDirFileFileFilter2.txt"); |
| 1092 |
1
|
final File file3 = new File(dir2, "testDeleteDirFileFileFilter_3.txt"); |
| 1093 |
1
|
assertTrue(dir2.mkdirs()); |
| 1094 |
|
|
| 1095 |
1
|
IoUtility.saveFile(file1, "File 1", "ISO-8859-1"); |
| 1096 |
1
|
IoUtility.saveFile(file2, "File 2", "ISO-8859-1"); |
| 1097 |
1
|
IoUtility.saveFile(file3, "File 3", "ISO-8859-1"); |
| 1098 |
1
|
assertTrue(IoUtility.deleteDir(dir1, new FileFilter() { |
| 1099 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1100 |
3
|
public boolean accept(final File pathname) {... |
| 1101 |
3
|
return pathname.toString().indexOf("testDeleteDirFileFileFilter_") >= 0; |
| 1102 |
|
} |
| 1103 |
|
})); |
| 1104 |
1
|
assertTrue(dir1.exists()); |
| 1105 |
1
|
assertFalse(dir2.exists()); |
| 1106 |
1
|
assertFalse(file1.exists()); |
| 1107 |
1
|
assertFalse(file2.exists()); |
| 1108 |
1
|
assertFalse(file3.exists()); |
| 1109 |
|
} |
| 1110 |
|
|
| 1111 |
|
} |