英文:
How to get the value from the s3 input stream in java
问题
我正在尝试获取值:
public char getTs() throws IOException {
S3ObjectInputStream ts = null;
int i;
ts = (S3ObjectInputStream) s3Services.getResourceStream(fileURL.toString());
while ((i = ts.read()) != -1) {
c = (char) i;
LOGGER.info("req time {}", c);
}
return c;
}
我得到的值是以位为单位的,如何一次获取整个值?
是否适合使用数组?
我的输出:
req time 0
req time 1
req time -
req time 0
req time 1....等等
预期输出:
req time 01-01-2000 03:10:10
英文:
I am trying to get value here :
public char getTs() throws IOException {
S3ObjectInputStream ts = null;
int i;
ts = (S3ObjectInputStream) s3Services.getResourceStream(fileURL.toString());
while ((i = ts.read()) != -1) {
c = (char) i;
LOGGER.info("req time {} ", c);
}
return c;
}
The value I am getting is in bits, how to get the whole value at once?
Is it suitable to use an array?
My Output :req time 0
req time 1
req time -
req time 0
req time 1.... and so on
My expected output is :req time 01-01-2000 03:10:10
答案1
得分: 1
你可以将 S3ObjectInputStream
包装在 InputStreamReader
中,然后将 InputStreamReader
包装在 BufferedInputStream
中。这样,你可以逐行读取对象:
var reader = new BufferedReader(new InputStreamReader(ts));
var line = reader.readLine();
此外,还可以查看 Apache Commons IO,该库提供了额外方便的流、读取器和工具。
英文:
You could wrap the S3ObjectInputStream
within an InputStreamReader
and the InputStreamReader
within a BufferedInputStream
. That way you can read the object line by line:
var reader = new BufferedReader(new InputStreamReader(ts));
var line = reader.readLine();
Also check out Apache Commons IO which provide additional convenient streams and readers and utilities.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论