我遇到了一些进程包装的问题,它只发生在Windows XP中.这段代码在Windows 7中完美运行.我真的很难过为什么XP中的流是空的.我也尝试使用Process.Exec()的String []版本,它没有任何区别.
我使用以下类从进程'STDOUT和STDERR(每个流的一个实例)中读取:
import java.util.*;
import java.io.*;
public class ThreadedStreamReader extends Thread{
InputStream in;
Queue messageQueue;
public ThreadedStreamReader(InputStream s, Queue q)
{
in = s;
messageQueue = q;
}
public void run()
{
try
{
BufferedReader r = new BufferedReader(new InputStreamReader(in));
String line = null;
while((line = r.readLine()) != null)
{
synchronized(messageQueue)
{
messageQueue.add(line);
}
}
}catch(Exception e)
{
System.err.println("Bad things happened while reading from a stream");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里使用它:
Process p = Runtime.getRuntime().exec("test.exe");
Queue<String> q = …Run Code Online (Sandbox Code Playgroud) 我试图将用户上传的图像存储到具有LONGBLOB属性的数据库中...我遇到了一个问题,PreparedStatement其中有两个方法来设置blob:
public void setBinaryStream(int parameterIndex, InputStream x)
public void setBlob(int parameterIndex, Blob x)
public void setBlob(int parameterIndex, InputStream inputStream)
现在的问题是我有一个BufferedImage必须转换成Blob或InputStream上传的对象......
如何在不丢失原始图像格式或质量的情况下执行此操作?
搜索1小时后,我找不到解决问题的方法.
我想将文件从sdcard移动到assets文件夹,并且还覆盖assets文件夹中的现有文件(这两个文件都是sqlite数据库,它们具有相同的名称,数据只有一点点差别)
??
我正在尝试编写一个函数,它接受File对象,偏移量和字节数组参数,并将该字节数组写入Java中的File对象.
所以函数看起来像
public void write(File file, long offset, byte[] data)
Run Code Online (Sandbox Code Playgroud)
但问题是offset参数是long类型,所以我不能使用OutputStream的write()函数,它将整数作为偏移量.
与跳过(长)的InputStream不同,似乎OutputStream无法跳过文件的第一个字节.
有没有好办法解决这个问题?
谢谢.
我正在开发一个图像抓取应用程序.我正在获取URL
URL imageUrl = new URL(imageSource);
Run Code Online (Sandbox Code Playgroud)
然后我用这个URL创建一个InputStream:
InputStream is = new URL(imageUrl.toString()).openStream();
Run Code Online (Sandbox Code Playgroud)
在此之后,我想创建一个ImageInputStream来确定ImageIO读者.
ImageInputStream iis = ??????
Run Code Online (Sandbox Code Playgroud)
但我无法初始化这个.我可以为ImageInputStream实现URL或InputStream吗?
在我的情况下,我必须从我的网络应用程序资源文件夹中下载图像.现在我使用以下代码通过URL下载图像.
url = new URL(properties.getOesServerURL() + "//resources//WebFiles//images//" + imgPath);
filename = url.getFile();
is = url.openStream();
os = new FileOutputStream(sClientPhysicalPath + "//resources//WebFiles//images//" + imgPath);
b = new byte[2048];
while ((length = is.read(b)) != -1) {
os.write(b, 0, length);
}
Run Code Online (Sandbox Code Playgroud)
但是我想要一次操作来一次读取所有图像并为此创建一个zip文件.我不太了解序列输入流和zip输入流的使用,所以如果可以通过这些,请告诉我.
我将从第三方库获取输入流到我的应用程序.我必须将此输入流写入文件.
以下是我尝试过的代码段:
private void writeDataToFile(Stub stub) {
OutputStream os = null;
InputStream inputStream = null;
try {
inputStream = stub.getStream();
os = new FileOutputStream("test.txt");
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
os.write(bytes, 0, read);
}
} catch (Exception e) {
log("Error while fetching data", e);
} finally {
if(inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
log("Error while closing input stream", e);
}
}
if(os != null) …Run Code Online (Sandbox Code Playgroud) 我面临一条错误消息
java.io.EOFException
at libcore.io.Streams.readAsciiLine(Streams.java:203)
at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:579)
at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:827)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
com.example.rest.MainActivity.excutePost(MainActivity.java:354)
at com.example.rest.MainActivity$1.run(MainActivity.java:86)
at java.lang.Thread.run(Thread.java:841)
Run Code Online (Sandbox Code Playgroud)
我的代码是
URL url = new URL(url);
con = (HttpsURLConnection) url.openConnection();
con.setRequestProperty("Content-Language", "en-US,en;q=0.8");
con.setRequestProperty("userID", "user20@yahoo.com");
con.setRequestProperty("password", "xyz123");
con.setRequestMethod(HttpDelete.METHOD_NAME);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "*/*");
con.addRequestProperty("Accept-Encoding", "gzip");
InputStream inputStream = con.getInputStream();
String convertInputStreamToString = convertInputStreamToString(inputStream);
Run Code Online (Sandbox Code Playgroud)
我试过这些链接
我在内存中创建PDF文档作为OutputStreams.这些应该上传到S3.我的问题是,它无法创建一个PutObjectRequest从OutputStream(直接按这个线程在AWS开发论坛).我aws-java-sdk-s3在Dropwizard应用程序中使用v1.10.8 .
到目前为止我能看到的两个解决方法是:
OutputStream到a InputStream并接受使用两倍量的RAM.OutputStream到一个InputStream并接受额外线程的开销(参见这个答案)如果我找不到更好的解决方案,我会选择#1,因为在我的设置中,它看起来好像能够比线程/ CPU更容易买得起额外的内存.
到目前为止,我是否还有其他任何可能更有效的方式来实现这一目标?
编辑:
我OutputStreams为ByteArrayOutputStream小号
我试图通过使用按钮设置默认壁纸,但出于某种原因,当我在OnCreate方法中设置InputStream时,我得到此错误"raw type of raw".我正在引用drawable文件夹并使用drawable文件夹中的icon.png图像.我正在按照NewBoston系列中的教程进行操作,它似乎对Travis工作正常,但由于某种原因,我在Android Studio中无法工作.可能是什么错误?谢谢
Camera.java:
package com.example.user.cameraapplication;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Switch;
import java.io.IOException;
import java.io.InputStream;
/**
* Created by user on 16-08-2015.
*/
public class Camera extends Activity implements View.OnClickListener{
ImageView iv;
Button b1,b2;
ImageButton img;
Intent i;
final static int cameractivity = 0;
Bitmap b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photo);
inititalize();
InputStream is = getResources().openRawResource(R.drawable.icon);
b = …Run Code Online (Sandbox Code Playgroud) inputstream ×10
java ×9
android ×3
outputstream ×2
amazon-s3 ×1
blob ×1
deadlock ×1
eclipse ×1
file ×1
httpclient ×1
image ×1
io ×1
process ×1
rest ×1
spring-mvc ×1
web-services ×1