草庐IT

inputstreams

全部标签

java - 将 InputStream 写入 HttpServletResponse

我有一个要写入HttpServletResponse的InputStream。有这种方法,由于使用了byte[],耗时太长InputStreamis=getInputStream();intcontentLength=getContentLength();byte[]data=newbyte[contentLength];is.read(data);//responsehereistheHttpServletResponseobjectresponse.setContentLength(contentLength);response.write(data);我想知道在速度和效率方面最好

java - 为什么从 Process 的 InputStream 中读取数据是可用的

Java:Processp=Runtime.getRuntime().exec("myCommand");finalInputStreamin=p.getInputStream();newThread(){publicvoidrun(){intb;while((b=in.read())!=-1)//Blockshereuntilprocessterminates,why?System.out.print((char)b);}}.start();CPP:#include#includeintmain(intargc,char**argv){printf("round1\n");//Att

java - inputstream.available() 始终为 0

我不知道我的代码发生了什么。我没有收到任何错误,也没有任何回应。我正在将数据写入串行端口并通过激活port.notifyOnDataAvailable(true);等待响应,但未触发此事件并且inputstream.available()始终返回0。可能出了什么问题?我在Linux中使用RXTX。编辑packagetestConn;importforms_helper.global_variables;importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStream;importjava.i

java - 如何将 InputStream 转换为 Source?

我想使用存储在我的设备上的xsd架构文件来验证xml文档。这是我的示例代码:SchemaFactoryfactory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);//schemafileonmydeviceInputStreamisSchema=context.getResources().openRawResource(xsd_file);//InputStream=>SourceconversionSourceschemaSource=????Schemaschema=factory.newSchema

java - 在android中从HttpURLConnection获取InputStream时获取UnknownLengthHttpInputStream

HttpURLConnection.getInputStream()给出UnknownLengthHttpInputStream并且由于此Document解析引发SAX解析器异常。以下是代码try{URLurl=newURL(uri);HttpURLConnectionconnection=(HttpURLConnection)url.openConnection();connection.setRequestMethod("GET");connection.setRequestProperty("Accept","application/xml");InputStreamxml=co

java - InputStream 到 JsonObject - GSON

我在将结果从这个api转换为JsonObject时遇到了很多麻烦。无论我尝试做什么,“结果”都保持为空。URLurl=newURL(urlString);InputStreaminput=url.openStream();Readerreader=newInputStreamReader(in,"UTF-8");JsonResultresult=newGson().fromJson(reader,JsonResult.class);JsonResult类publicclassJsonResult{privateStringstatus;privateMetameta;privateAr

java - 将大型 JSON (InputStream) 放入 String 时出现内存不足错误

我从Web服务接收gzip后的JSON,然后将其解压缩(解压缩后的JSON大小为3.2MB)。我需要将收到的InputStream转换为String,然后我可以创建JSONObject并解析它。我用这段代码来做:publicstaticStringInputStreamToString(InputStreamin)throwsIOException{BufferedInputStreambis=newBufferedInputStream(in);ByteArrayOutputStreambuf=newByteArrayOutputStream();intresult=bis.read

java - 使用 InputStream 读取文本文件

我怎样才能像在android应用程序中那样读取文本文件:"1.somethingwritten2.inthisfile3.istobereadby4.theInputStream..."所以我可以返回一个字符串,如:"somethingwritten\ninthisfile\nistobereadby\ntheInputStream"我想到的是(伪代码):makeaninputstreamis=getAssest().open("textfile.txt");//intryandcatchforloop{string=is.read()andifitequals"."(i.e.from

Android - 从 Uri 到 InputStream 再到字节数组?

我正在尝试从AndroidUri获取字节数组。我有以下代码,但它一直告诉我字节数组有61个字节长,即使文件很大-所以我认为它可能会将Uristring变成字节数组,而不是文件:(Log.d(LOG_TAG,"fileUriString="+fileUriString);Uritempuri=Uri.parse(fileUriString);InputStreamis=cR.openInputStream(tempuri);Stringstr=is.toString();byte[]b3=str.getBytes();Log.d(LOG_TAG,"lenofdatais"+imageBy

android - 将文件从外部存储加载到 Inputstream

我的外部目录中有一个视频文件。我怎样才能将它加载到输入流变量。目前我正在读取res/raw文件夹中的文件,但我想从sdcard中读取它。我也不知道文件的名称,但它的路径将通过Intent接收。检查以下代码publicclassSonicTestextendsActivity{VideoViewvideoView;Stringuri;InputStreamsoundFile;Filefile;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContent