简体   繁体   English

获取Java中InputStream的大小

[英]get size of InputStream in Java

I am trying to encrypt an InputStream which I am getting from FileItem.getInputStream(); 我正在尝试加密从FileItem.getInputStream();获得的InputStream FileItem.getInputStream(); and I want to know the encrypted stream's length. 而且我想知道加密流的长度。

If it would be a simple FileInputStream , I could have tried File#length() or FileInputStream#getChennal().size() though not sure even those would have given me exactly what I want, but, in this case what I have is an InputStream (the encrypted one) and I want to find length of the same, I tried searching on Internet but there I could not find any efficient solution to that. 如果它是一个简单的FileInputStream ,我可以尝试File#length()FileInputStream#getChennal().size()尽管不确定那些甚至是否可以准确地给出我想要的东西,但是在这种情况下,我拥有的是一个InputStream (经过加密的输入流),我想找到相同的长度,我尝试在Internet上搜索,但是在那里找不到任何有效的解决方案。

Please help 请帮忙

You have to read the whole stream for that. 您必须阅读整个流程。 Streams are probably not even complete when you start reading from them, so the size may not be known at that time. 当您开始从流中读取数据时,它们甚至可能还不完整,因此当时可能不知道其大小。

You can output whats in InputStream and get the length 您可以在InputStream中输出内容并获取长度

ObjA = new ObjA;

while( more message to read ){
ObjA = inputStreamObj.read();
}

System.out.println(ObjA.length());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM