FileSplitter { public static File[] spliteFile(File inputFile) throws Exception { return spliteFile(inputFile, DEFAULT_CHUNK_SIZE, inputFile.getParentFile()); }  static File[] spliteFile(File inputFile); static File[] spliteFile(File inputFile, long bytesPerChunk); static File[] spliteFile(File inputFile, long bytesPerChunk, File outputDir); static File recomposeFile(File[] inputFiles, File outputFile); static int DEFAULT_CHUNK_SIZE; static int BUFFER_SIZE; static String CHUNK_SEPARATOR; }
@Test @Category(org.datavaultplatform.SlowTest.class) public void testSplit500MBFile() { System.out.println( "\nStart testSplit500MBFile"); try{ File inputFile = new File(bigFileResources, "500MB_file"); long bytesPerChunk = 100 * 1000 * 1000; long start = System.currentTimeMillis(); File[] chunks = FileSplitter.spliteFile(inputFile, bytesPerChunk, tempDir); long elapsedTimeMillis = System.currentTimeMillis()-start; float elapsedTimeSec = elapsedTimeMillis/1000F; System.out.println( "Total time: " + elapsedTimeSec + "sec"); assertEquals(5, chunks.length); for(File chunk : chunks){ assertEquals(bytesPerChunk, chunk.length()); chunk.delete(); } } catch(SecurityException se) { se.printStackTrace(); fail(se.getMessage()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test @Category(org.datavaultplatform.SlowTest.class) public void testSplit500MBFileWithExtraBytes() { System.out.println( "\nStart testSplit500MBFileWithExtraBytes"); try{ File inputFile = new File(bigFileResources, "500MB_file"); long bytesPerChunk = 150 * 1000 * 1000; long start = System.currentTimeMillis(); File[] chunks = FileSplitter.spliteFile(inputFile, bytesPerChunk, tempDir); long elapsedTimeMillis = System.currentTimeMillis()-start; float elapsedTimeSec = elapsedTimeMillis/1000F; System.out.println( "Total time: " + elapsedTimeSec + "sec"); assertEquals(4, chunks.length); int pos; long lastBytesChunk = 50 * 1000 * 1000; for(pos=0; pos < chunks.length; pos++){ File chunk = chunks[pos]; if(pos < 3){ assertEquals(bytesPerChunk, chunk.length()); } else { assertEquals(lastBytesChunk, chunk.length()); } chunk.delete(); } } catch(SecurityException se) { se.printStackTrace(); fail(se.getMessage()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test @Category(org.datavaultplatform.SlowTest.class) public void testSplitGigaBytesFile() { System.out.println( "\nStart testSplitGigaBytesFile"); try{ File inputFile = new File(bigFileResources, "1.5GB_file"); long bytesPerChunk = 500 * 1000 * 1000; long start = System.currentTimeMillis(); File[] chunks = FileSplitter.spliteFile(inputFile, bytesPerChunk, tempDir); long elapsedTimeMillis = System.currentTimeMillis()-start; float elapsedTimeSec = elapsedTimeMillis/1000F; System.out.println( "Total time: " + elapsedTimeSec + "sec"); assertEquals(3, chunks.length); for(File chunk : chunks){ assertEquals(bytesPerChunk, chunk.length()); chunk.delete(); } } catch(SecurityException se) { se.printStackTrace(); fail(se.getMessage()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test @Category(org.datavaultplatform.SlowTest.class) public void testSplitGigaBytesFileWithExtraBytes() { System.out.println( "\nStart testSplitGigaBytesFileWithExtraBytes"); try{ File inputFile = new File(bigFileResources, "1.5GB_file"); long bytesPerChunk = 1000 * 1000 * 1000; long start = System.currentTimeMillis(); File[] chunks = FileSplitter.spliteFile(inputFile, bytesPerChunk, tempDir); long elapsedTimeMillis = System.currentTimeMillis()-start; float elapsedTimeSec = elapsedTimeMillis/1000F; System.out.println( "Total time: " + elapsedTimeSec + "sec"); assertEquals(2, chunks.length); int pos; long lastBytesChunk = 500 * 1000 * 1000; assertEquals(bytesPerChunk, chunks[0].length()); chunks[0].delete(); assertEquals(lastBytesChunk, chunks[1].length()); chunks[1].delete(); } catch(SecurityException se) { se.printStackTrace(); fail(se.getMessage()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }