确定InputStream的大小(Determine the size of an InputStream)
我目前的情况是:我必须读取一个文件并将内容放入
InputStream
。 之后,我需要将InputStream
的内容放入一个字节数组中,这样就需要(据我所知)InputStream
的大小。 有任何想法吗?根据要求,我将显示从上传的文件创建的输入流
InputStream uploadedStream = null; FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); java.util.List items = upload.parseRequest(request); java.util.Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { uploadedStream = item.getInputStream(); //CHANGE uploadedStreambyte = item.get() } }
该请求是一个
HttpServletRequest
对象,它类似于FileItemFactory
,ServletFileUpload
来自Apache Commons FileUpload包。My current situation is: I have to read a file and put the contents into
InputStream
. Afterwards I need to place the contents of theInputStream
into a byte array which requires (as far as I know) the size of theInputStream
. Any ideas?As requested, I will show the input stream that I am creating from an uploaded file
InputStream uploadedStream = null; FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); java.util.List items = upload.parseRequest(request); java.util.Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { uploadedStream = item.getInputStream(); //CHANGE uploadedStreambyte = item.get() } }
The request is a
HttpServletRequest
object, which is like theFileItemFactory
andServletFileUpload
is from the Apache Commons FileUpload package.
原文:https://stackoverflow.com/questions/1119332
最满意答案
尝试使用
Start-Transcript
和Stop-Transcript
cmdlet。您也可以使用Start-Transcript for ISE Editor模块,因为这些CmdLet在ISE中不能以本地方式工作 。
Try with
Start-Transcript
andStop-Transcript
cmdlet.You can also use Start-Transcript for ISE Editor module because these CmdLet don't work natively in ISE.
相关问答
更多-
linux下的shellscript[2022-02-11]
filename=${fileuser:-"filename"} filename 变量未设定或者为空,filename取"-"后面的值;否则filename=$fileuser -
Windows Shellscript中“脚本”命令的等效功能?(Equivalent of “script” command in Windows Shellscript?)[2022-03-28]
尝试使用Start-Transcript和Stop-Transcript cmdlet。 您也可以使用Start-Transcript for ISE Editor模块,因为这些CmdLet在ISE中不能以本地方式工作 。 Try with Start-Transcript and Stop-Transcript cmdlet. You can also use Start-Transcript for ISE Editor module because these CmdLet don't work na ... -
将所有变量从一个shellscript传递到另一个shellscript?(Pass all variables from one shell script to another?)[2021-07-18]
你有两个选择: 在执行第二个脚本之前,将该变量设置为环境变量( export TESTVARIABLE )。 来源于第二个脚本,即 . test2.sh ,它将在同一个shell中运行。 这将让您轻松地共享更多复杂的变量,例如数组,但也意味着其他脚本可以修改源shell中的变量。 更新: 要使用export设置环境变量,可以使用现有变量: A=10 # ... export A 这应该在bash和sh 。 bash也允许它像这样组合: export A=10 这也可以在我的 sh (这恰好是bash , ... -
这对你有用 for i in `ls jars/*.jar`; do export CLASSPATH=$CLASSPATH:$i; done export CLASSPATH=.:$CLASSPATH javac `find * -name *.java` This shall work for you for i in `ls jars/*.jar`; do export CLASSPATH=$CLASSPATH:$i; done export CLASSPATH=.:$C ...
-
您可以在脚本中定义这样的别名: alias rm='echo SAFE' 默认情况下,别名仅在交互式shell中起作用,因此您必须使用以下方法更改此行为: shopt -s expand_aliases 在您的脚本中并获取另一个脚本(您无法更改的脚本): source the_other_script.sh 要么 . the_other_script.sh 除非另一个脚本在子shell中运行rm ,否则这将起作用。 另一个更安全的方法是创建自己的rm命令,它什么都不做(或只打印出它的参数,以便你知道 ...
-
以下脚本(如果路径是正确的)打印出mongoexport版本。 #!/bin/sh /path/to/mongoexport --version 您可以使用脚本中命令行中通常使用的任何其他命令。 你可以在这里找到这些: https : //docs.mongodb.com/manual/reference/program/mongoexport/ The following script (if the path would be correct) prints out the mongoexport v ...
-
这样的东西就足够了。 ver | findstr /i /c:"Version 6.3" >nul && goto :set_win81 以下是我为此任务所做的一些代码: @echo off set "windows=" VER | find " 4.1." > nul && set windows=W98 VER | find " 4.0." > nul && set windows=NT VER | find " 5.0." > nul && set windows=W2K VER | find ...
-
我试着用下面的代码,它在我的情况下工作正常。 cmd1 := exec.Command("/bin/bash","-c", "yes") cmd2 := exec.Command("path to install.sh", "2>&1 >/dev/null") cmd2.Stdin, _ = cmd1.StdoutPipe() cmd2.Stdout = os.Stdout _ = cmd2.Start() _ = cmd1.Run() _ = cmd2.Wait() I tried with the b ...
-
我建议你在家安装cygwin 。 I suggest you install cygwin at home.
-
将shellscript中的行之间的空格作为命令[重复](Space between lines in shellscript being taken as a command [duplicate])[2024-03-22]
当您使用od -xc file转储od -xc file ,您的注释会添加行使用DOS行尾( \r\n )的od -xc file 。 为避免这种情况,您应该确保编辑器使用Unix行尾( \n )。 要将其修复到现有文本文件,您可以使用tr : tr -d '\r' < dos_file > unix_file Your comment add the precision that your lines use DOS end of lines (\r\n) when you dump it with o ...