所以我正在编写一个一次性脚本供我个人单独使用,我希望能够看到这个过程的进展情况.基本上我正在处理几千个媒体发布并将它们发送到我们的新CMS.
所以我没有锤击CMS,我sleep在每5次请求后制作脚本几秒钟.
我希望 - 当脚本正在执行时 - 能够看到我echo告诉我脚本将要睡眠或者最后一次与webservice的交易成功.
这可能在PHP?
谢谢你的帮助!
伊恩
有趣的情况.我有一段代码创建了几个ZipOutputStreams.在我考虑写任何东西之前作为安全检查,我检查我的输出流是否已正确初始化:
ZipOutputStream countStream = null;
File countFile = null;
// other files
try {
countFile =
new File(savePath.getCanonicalPath() + savePath.separator + outputTag
+ "_COUNT_OUTPUTS.zip");
// other files
} catch (Exception e) {
outputLog.add("UNABLE TO FIND SAVE PATH");
return util.FILE_INVALID;
}
try {
// prepare outputs
if (countFile.exists() == true) {
countFile.delete();
} else {
}
countStream = new ZipOutputStream(new FileOutputStream(countFile));
// other files
} catch (Exception e) {
e.printStackTrace();
outputLog.add("UNABLE TO CREATE OUTPUT FILES");
return util.FILE_SAVE_FAIL;
}
if (countStream == …Run Code Online (Sandbox Code Playgroud) 在运行进程时,如何将其输出传输到System.out它并输入到System.in:
Process p = Runtime.getRuntime().exec("cubc.exe");
// do something with p.getOutputStream())
Run Code Online (Sandbox Code Playgroud)
编辑:我想我解释错了; 我不想输入程序,我希望用户输入程序,我不想读取输出,我希望用户读取输出.
我正在编写一个程序,将数据输出到.txt文件,可以由一个人使用NotePad等程序读取.也许不一定是ASCII,但用户可以理解的东西.
我使用哪一种?
我有这个赋值,要求我专门使用一个OutputStream子类,所以Writer不是一个选项.
课程概述
我有这个简单的服务器/客户端应用程序 我正在尝试让服务器通过OutputStream(FileOutputStream,OutputStream,ObjectOutputStream等)发送文件,并在将其保存到实际文件之前在客户端接收它.问题是,我已经尝试过这样做,但它一直在失败.每当我创建文件并将从服务器收到的对象写入其中时,我都会得到一个破碎的图像(我只是将它保存为jpg,但这无关紧要).以下是最有可能出现故障的代码部分(您在此处看到的所有看似未声明的对象都已预先声明):
服务器:
ObjectOutputStream outToClient = new ObjectOutputStream(
connSocket.getOutputStream());
File imgFile = new File(dir + children[0]);
outToClient.writeObject(imgFile);
outToClient.flush();
Run Code Online (Sandbox Code Playgroud)
客户:
ObjectInputStream inFromServer = new ObjectInputStream(
clientSocket.getInputStream());
ObjectOutputStream saveImage = new ObjectOutputStream(
new FileOutputStream("D:/ServerMapCopy/gday.jpg"));
saveImage.writeObject(inFromServer.readObject());
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是我无法在没有损坏文件的情况下正确地通过流获取对象.
可能重复:
C++:"std :: endl"vs"\n"
我有一个简单的程序,我测试过,我意识到这endl对我的程序造成了严重破坏.使用ENDL,我的程序在运行100个+ MS与工作时'\n',时间降至〜50毫秒.有谁能说出为什么会有这样的差异?
PS我确实阅读了其他帖子,以某种方式解释了他们每个人在做什么,但std::flush确实花了这么多时间?
或者还有其他可能的解释吗?
我正在使用遗留的Java应用程序,在许多文件中,使用套接字和流,其中套接字正在关闭而不是流,这是在关闭套接字之前关闭所有流所必需的.因为我收到"太多的打开文件错误",这个错误是因为没有关闭流.....
关闭套接字会自动关闭流吗?
我正在尝试开发一个Android应用程序,将图像从一个设备传输到另一个设备.然后,接收到的图像将显示在我的应用程序内的ImageView上.为了完成我的任务,我想发送一个位图的字节数组.我能够在imageview上获得第一张图片.但是,只要我点击按钮发送另一个图像,应用程序就无法发送位图.它向我显示了一个异常"java.io.IOException:Service fiscovery failed".要成功发送任何图像,我需要在接收/远程设备上重新启动我的应用程序.任何人都可以建议解决mu问题.logcat也包含在下面.
建立连接的代码:
private class StartConnectionThread extends Thread{
private final BluetoothSocket bluetoothSocket;
private final BluetoothDevice bluetoothDevice;
public StartConnectionThread(BluetoothDevice device){
BluetoothSocket tempBluetoothSocket=null;
bluetoothDevice=device;
try
{
System.out.println(uuid);
tempBluetoothSocket=device.createRfcommSocketToServiceRecord(uuid);
}
catch(IOException ioException)
{
}
bluetoothSocket=tempBluetoothSocket;
}
@Override
public void run() {
// TODO Auto-generated method stub
bluetoothAdapter.cancelDiscovery();
try
{
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
bluetoothSocket.connect();
}
catch(IOException ioException)
{
System.out.println("bluetoothSocketInThread failed");
try
{
bluetoothSocket.close();
}
catch(IOException cancelIOException)
{ …Run Code Online (Sandbox Code Playgroud) 我有一个用于下载文件的Web界面.当请求进入时,我的glassfish服务器从Web服务流式传输文件,然后将内容写入输出流.我的代码工作正常,除非文件大小变得非常大(例如超过200 MB),它在浏览器中挂起显示0%已下载并且永远不会下载文件.
当我在while循环中移动flush()方法时,它也适用于大文件.我不确定将flush()放入循环是否有问题.不知道这件事实际上是如何运作的.我的代码如下:
HttpURLConnection conn = (HttpURLConnection) downloadUri.toURL().openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/pdf");
if (conn.getResponseCode() == 200) {
ServletOutputStream output;
try (InputStream inputStream = conn.getInputStream()) {
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.setContentType("application/octet-stream");
response.setHeader("Content-Length", conn.getHeaderField("Content-Length"));
response.setHeader("Content-Disposition", "attachment; filename=\"" + abbr + ".pdf\"");
output = response.getOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
}
output.flush();
output.close();
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?.感谢您对此进行调查.
我有以下问题:我有一个HttpServlet创建一个文件,并将其返回给用户,必须下载它
byte[] byteArray = allegato.getFile();
InputStream is = new ByteArrayInputStream(byteArray);
Base64InputStream base64InputStream = new Base64InputStream(is);
int chunk = 1024;
byte[] buffer = new byte[chunk];
int bytesRead = -1;
OutputStream out = new ByteArrayOutputStream();
while ((bytesRead = base64InputStream.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我有一个byteArray对象是一个字节数组(byte [] byteArray),我以这种方式将其转换为文件:
首先,我将其转换为InputStream对象.
然后我将InputStream对象转换为Base64InputStream.
最后,我将这个Base64InputStream写在ByteArrayOutputStream对象(OutputStream out对象)上.
我认为到目前为止它应该没问题(是否可以,或者我在文件创建中遗漏了什么?)
现在我的servlet必须将此文件作为下载文件返回(因此用户必须将下载内容接收到浏览器中).
那么我该怎么做才能获得这种行为呢?我认为我必须将此OutputStream对象放入Servlet响应中,例如:
ServletOutputStream stream = res.getOutputStream();
Run Code Online (Sandbox Code Playgroud)
但我不知道它究竟是怎么做到的?我是否还要为文件设置特定的MIME类型?
outputstream ×10
java ×7
inputstream ×4
file ×2
stream ×2
android ×1
ascii ×1
bluetooth ×1
c++ ×1
flush ×1
httpresponse ×1
java-ee ×1
object ×1
php ×1
progress-bar ×1
serversocket ×1
servlets ×1
sockets ×1
streaming ×1
warnings ×1
zip ×1