Здравствуйте, я решил эту проблему самостоятельно, разделив File на более мелкие куски и используя MultiResourcePartitioner для чтения файлов чанков.
Ниже приведена моя программа-сплиттер
package com.cookmedical.batch.utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FileSplitter {
private static Logger logger = LoggerFactory.getLogger(FileSplitter.class);
public static String NEWLINE = System.getProperty("line.separator");
public static int MAX_FILE_RECORDS = 50;
public void split(File masterFile) throws IOException {
try {
// opens the file in a string buffer
BufferedReader bufferedReader = new BufferedReader(new FileReader(masterFile));
StringBuffer stringBuffer = new StringBuffer();
// performs the splitting
String fileLine;
int fileLineNumber = 0;
int rowCounter = 0;
int partitionCounter = 1;
String fileHeader = "";
String parentFolder = masterFile.getParent();
String fileName = StringUtils.substringBeforeLast(masterFile.getName(), ".csv") + "_";
while ((fileLine = bufferedReader.readLine()) != null) {
if (fileLineNumber == 0) {
fileHeader = fileLine;
}
if (rowCounter >= MAX_FILE_RECORDS) {
saveFilePartition(parentFolder, fileName+partitionCounter+".csv",masterFile.lastModified(),stringBuffer);
rowCounter = 0;
partitionCounter++;
stringBuffer = new StringBuffer();
stringBuffer.append(fileHeader);
stringBuffer.append(NEWLINE);
stringBuffer.append(fileLine);
stringBuffer.append(NEWLINE);
} else {
stringBuffer.append(fileLine);
stringBuffer.append(NEWLINE);
}
rowCounter++;
fileLineNumber++;
}
saveFilePartition(parentFolder, fileName+partitionCounter+".csv",masterFile.lastModified(),stringBuffer);
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void saveFilePartition(String parentFolder, String fileName, long lastModifiedTime, StringBuffer fileContent) throws IOException {
File splitFolder = new File(parentFolder + File.separator + "splitFolder");
splitFolder.mkdir();
FileWriter output = null;
try {
splitFolder = new File(splitFolder + File.separator + fileName);
splitFolder.setLastModified(lastModifiedTime);
output = new FileWriter(splitFolder);
output.write(fileContent.toString());
// System.out.println("file " + file.getAbsolutePath() +
// " written");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
output.close();
} catch (IOException e) {
// do nothing the file wasn't been even opened
}
}
}
}