From b2c20113f2f27b18f46ee29a017b54d184d8b5f4 Mon Sep 17 00:00:00 2001 From: Anil Koyuncu Date: Fri, 20 Apr 2018 14:42:05 +0200 Subject: [PATCH] split chunks --- .../cluster/CalculatePairs.java | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/main/java/edu/lu/uni/serval/FixPatternParser/cluster/CalculatePairs.java b/src/main/java/edu/lu/uni/serval/FixPatternParser/cluster/CalculatePairs.java index dccc9a6..cfcacaf 100644 --- a/src/main/java/edu/lu/uni/serval/FixPatternParser/cluster/CalculatePairs.java +++ b/src/main/java/edu/lu/uni/serval/FixPatternParser/cluster/CalculatePairs.java @@ -96,25 +96,9 @@ public class CalculatePairs { byte [] buf = new byte[0]; String line = null; try { - FileOutputStream fos = new FileOutputStream(outputPath + "/" +pjName+".txt"); - DataOutputStream outStream = new DataOutputStream(new BufferedOutputStream(fos)); - - - - for (int i = 0; i < result.size(); i++) { - for (int j = i + 1; j < result.size(); j++) { - - - - line = String.valueOf(i) +"\t" + String.valueOf(j) + "\t" + result.get(i) + "\t" + result.get(j)+"\n"; - outStream.write(line.getBytes()); - - } - } - outStream.close(); -// FileChannel rwChannel = new RandomAccessFile(outputPath + "/" +pjName +".txt", "rw").getChannel(); -// ByteBuffer wrBuf = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, Integer.MAX_VALUE); -// int fileCounter = 0; +// FileOutputStream fos = new FileOutputStream(outputPath + "/" +pjName+".txt"); +// DataOutputStream outStream = new DataOutputStream(new BufferedOutputStream(fos)); +// // // // for (int i = 0; i < result.size(); i++) { @@ -123,22 +107,38 @@ public class CalculatePairs { // // // line = String.valueOf(i) +"\t" + String.valueOf(j) + "\t" + result.get(i) + "\t" + result.get(j)+"\n"; -// buf = line.getBytes(); -// if(wrBuf.remaining() > 500) { -// wrBuf.put(buf); -// }else{ -// log.info("Next pair dump"); -// fileCounter++; -// rwChannel = new RandomAccessFile(outputPath+"/" +pjName+String.valueOf(fileCounter)+".txt", "rw").getChannel(); -// wrBuf = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, Integer.MAX_VALUE); -// } -// -// -// +// outStream.write(line.getBytes()); // // } // } -// rwChannel.close(); +// outStream.close(); + int fileCounter = 0; + FileChannel rwChannel = new RandomAccessFile(outputPath + "/" +pjName +String.valueOf(fileCounter)+".txt", "rw").getChannel(); + ByteBuffer wrBuf = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, Integer.MAX_VALUE); + + + for (int i = 0; i < result.size(); i++) { + for (int j = i + 1; j < result.size(); j++) { + + + + line = String.valueOf(i) +"\t" + String.valueOf(j) + "\t" + result.get(i) + "\t" + result.get(j)+"\n"; + buf = line.getBytes(); + if(wrBuf.remaining() > 500) { + wrBuf.put(buf); + }else{ + log.info("Next pair dump"); + fileCounter++; + rwChannel = new RandomAccessFile(outputPath+"/" +pjName+String.valueOf(fileCounter)+".txt", "rw").getChannel(); + wrBuf = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, Integer.MAX_VALUE); + } + + + + + } + } + rwChannel.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) {