嗨,我正在使用[box] [1]
[1]:https://www.box.com/存储我的csv文件。文件大小为2GB。现在,我想处理文件的每个记录,并根据文件内容进行一些操作。
我做了什么:
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();
}
}
有了这个,我就能得到我已经上传到box.com的文件名。现在,我想阅读每个记录和过程。但是,我需要一个允许我访问文件块的API。
这个文件会按照开始和结束字节范围标志定义的块进行下载。但是由于块下载,我的记录很少破。意思是我没有完整的说法,下面是我的记录
16F11C78-D004-4600-8D28-445C087D2A7D
31C99F3D-D4C7-418A-9ACC-D9A382BCD53A
30C1AA92-B5B7-4ABF-A631-A8C150D90C4F
D9FC1DBF-B309-4BB1-8955-D9F48F643E97
我正进入(状态
16F11C78-D004-4600-8D28-445C087D2A7D
31C99F3D-D4C7-418A-9ACC-D9A382BCD53A
30C1AA92-B5B7-4ABF-A631-A8C150D90C4F
D9FC1DBF-
i.e. B309-4BB1-8955-D9F48F643E97
最后一行缺少一部分。我应该如何使用下载API进行管理?
目前,Box API无法做到这一点。您只能下载整个文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句