Hi i am using [box][1]
[1]: https://www.box.com/ to store my csv file. Size of file is 2GB. Now i want to process each record of file and do some operation based on file content.
what i did:
public class BoxConnector {
public static void main(String[] args) throws IOException {
BoxAPIConnection api = new BoxAPIConnection("My access token");
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
for (BoxItem.Info itemInfo : rootFolder) {
System.out.format("[%s] %s\n", itemInfo.getID(), itemInfo.getName());
BoxFile file = new BoxFile(api, itemInfo.getID());
BoxFile.Info info = file.getInfo();
try {
System.out.println(info.getSize());
File tmpFile = File.createTempFile("file", "temp");
FileOutputStream fsTmpStrem = new FileOutputStream(tmpFile);
long blockSize = 1000;
long roundChunks = info.getSize() / blockSize;
long startByteRange = 0;
long endByteRange = blockSize;
for (long start = 0; start < roundChunks; start++) {
file.downloadRange(fsTmpStrem, startByteRange, endByteRange);
processFile(tmpFile);
startByteRange = endByteRange;
endByteRange = endByteRange + blockSize;
}
//last download block
file.downloadRange(fsTmpStrem, blockSize * roundChunks, info.getSize());
processFile(tmpFile);
} finally {
}
}
}
private static void processFile(File tmpFile) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(tmpFile)));
String line = null;
while ((line = br.readLine()) != null) {
System.out.println("Process line record");
}
br.close();
//after each process lets delete the temp file
tmpFile.delete();
}
}
with this i am able to get the file name which i have uploaded to box.com. Now i want to read each record and process. However i need an API which allows me file chunk access .
with this files are getting downloaded as per chunk defined by start and end byte range flag.however due to chunk download i am getting few records broken . Meaning i am not getting complete line say below is my record
16F11C78-D004-4600-8D28-445C087D2A7D
31C99F3D-D4C7-418A-9ACC-D9A382BCD53A
30C1AA92-B5B7-4ABF-A631-A8C150D90C4F
D9FC1DBF-B309-4BB1-8955-D9F48F643E97
i am getting
16F11C78-D004-4600-8D28-445C087D2A7D
31C99F3D-D4C7-418A-9ACC-D9A382BCD53A
30C1AA92-B5B7-4ABF-A631-A8C150D90C4F
D9FC1DBF-
i.e. B309-4BB1-8955-D9F48F643E97
part from last line is missing.
How should i manage this with download API?