Tag: stream

如何识别java中InputStream的结尾

我想从服务器读取字节使用Socket程序,即我使用InputStream来读取字节。 如果我通过长度大小,我可以读取字节,但我不知道可能是什么长度。 所以我不能初始化字节数组。 我也试过while (in.read() != -1) ,我观察到它循环工作正常,当数据发送,但循环后的下一行是不可执行的,我觉得它仍然在寻找stream中的数据但没有数据。 如果我closures服务器连接,那么我的客户端将执行循环的下一行。 我不确定我哪里错了? this.in = socket.getInputStream(); int dataInt = this.in.read(); while(dataInt != -1){ System.out.print(","+i+"–"+dataInt); i++; dataInt = this.in.read(); } System.out.print("End Of loop"); 我得到的输出为: – ,1–0,2–62,3–96,4–131,5–142,6–1,7–133,8–2,9–16,10–48,11–56,12–1,13–0,14–14,15–128,16–0,17–0,18–0,19–48,20–0,21–0,22–0,23–0,24–0,25–1,26–0,27–0,28–38,29–114,30–23,31–20,32–70,33–3,34–20,35–1,36–133,37–48,38–51,39–49,40–52,41–49,42–55,43–49,44–52,45–52,46–54,47–55,48–50,49–51,50–52,51–48,52–53,53–56,54–51,55–48,56–48,57–57,58–57,59–57,60–57,61–57,62–57,63–57,64–56 但是没有输出: – End Of loop 请指导我如何closures循环? 期待您的回应。 提前感谢你们。

调整窗口大小时自动调整文本大小(字体大小)?

我一直在尝试(徒劳)build立一个页面,当我改变窗口大小时,页面的元素会resize。 我有工作在CSS图像没有问题,但我似乎无法完成相同的文字,我不知道它甚至可以在CSS中。 我似乎无法find一个jquery脚本来完成这一点。 当用户调整窗口大小时,我基本上希望页面能够dynamic且stream畅地缩放,而不必调用页面缩放。 这工作正常我的img divs通过CSS,但不是为文本,保持相同的大小。 有任何想法吗?

如何将文件内容读入istringstream?

为了提高从文件读取性能,我试图将一个大(几MB)文件的全部内容读入内存,然后使用istringstream来访问这些信息。 我的问题是,读取这些信息并将其“导入”stringstream的最佳方法是? 这种方法(见下文)的一个问题是,当创buildstringstream时,缓冲区被复制,内存使用量加倍。 #include <fstream> #include <sstream> using namespace std; int main() { ifstream is; is.open (sFilename.c_str(), ios::binary ); // get length of file: is.seekg (0, std::ios::end); long length = is.tellg(); is.seekg (0, std::ios::beg); // allocate memory: char *buffer = new char [length]; // read data as a block: is.read (buffer,length); // create string stream […]

从OKHTTP下载二进制文件

我在我的android应用程序中使用OKHTTP客户端联网。 这个例子展示了如何上传二进制文件。 我想知道如何用OKHTTP客户端获取二进制文件下载的inputstream。 这里是这个例子的列表: public class InputStreamRequestBody extends RequestBody { private InputStream inputStream; private MediaType mediaType; public static RequestBody create(final MediaType mediaType, final InputStream inputStream) { return new InputStreamRequestBody(inputStream, mediaType); } private InputStreamRequestBody(InputStream inputStream, MediaType mediaType) { this.inputStream = inputStream; this.mediaType = mediaType; } @Override public MediaType contentType() { return mediaType; } @Override public long […]

如何从命令行重置iOS模拟器?

我需要重置iPhone模拟器很多,并没有find一种方法来做到这一点,而不使用鼠标。 这是一件小事,但我真的很难这样做,并希望有一种方法来使用键盘快捷方式做到这一点。 更好的办法是从命令行重置它,所以我可以build立一个重置到部署脚本。 我对iOS或MacOS不是很熟悉。

什么是依赖属性?

.Net中的依赖属性是什么(特别是在WPF上下文中)。 与普通物业有什么不同?

PHP技术来查询APNs反馈服务器

有人可以澄清什么APNs(苹果推送通知)要求您如何查询它? 文档说,一旦build立连接就开始发送。 这是否意味着我不做一个fread()呢? 这是我目前的代码来尝试阅读它。 我没有把fread()放在一个循环中,因为我不知道什么响应表示“没有更多的logging要读取”,我不希望在我的服务器上出现无限循环。 <?php $apnsCert = 'HOHRO-prod.pem'; $streamContext = stream_context_create(); stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert); stream_context_set_option($streamContext, 'ssl', 'verify_peer', false); $apns = stream_socket_client('ssl://feedback.push.apple.com:2196', $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext); echo 'error=' . $error; echo 'errorString=' . $errorString; $result = fread($apns, 38); echo 'result=' . $result; fclose($apns); ?> 到目前为止,我所得到的是一个空回复。 没有错误,所以它正在连接。 我不知道是否空回答意味着没有数据,或者我的fread()是做错的方法。 谢谢

Vagrant错误:无法在Linux guest虚拟机中装入文件夹

我与Vagrant共享文件夹有一些问题,我的基本系统是Ubuntu 13.10桌面。 我不明白为什么我有这个错误是不是正确的configuration? 是NFS问题还是Virtualbox Guest Additions? 我曾尝试过不同的许多盒子,但同样的问题。 Failed to mount folders in Linux guest. This is usually because the "vboxsf" file system is not available. Please verify that the guest additions are properly installed in the guest and can work properly. The command attempted was: mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | […]

Java:作为控制stream的exception?

我听说使用控制stream的exception是不好的做法。 你觉得这怎么样? public static findStringMatch(g0, g1) { int g0Left = -1; int g0Right = -1; int g1Left = -1; int g1Right = -1; //if a match is found, set the above ints to the proper indices //… //if not, the ints remain -1 try { String gL0 = g0.substring(0, g0Left); String gL1 = g1.substring(0, g1Left); […]

自2013年2月6日起,通过“feed”连接使用Graph API发布到朋友的墙上

我的应用程序开始无法发布朋友的饲料项目。 我得到这个错误: Facebook request error: The operation couldn't be completed. (facebookErrDomain error 10000.), details: Error Domain=facebookErrDomain Code=10000 "The operation couldn't be completed. (facebookErrDomain error 10000.)" UserInfo=0xa26e990 {error={ code = 200; message = "(#200) Feed story publishing to other users is disabled for this application"; type = OAuthException; }} 我没有改变应用程序中的任何东西。 也许这与Facebook升级有关? 这些是我连接到Facebook的权限: [appDelegate.facebook authorize:[NSArray arrayWithObjects:@"publish_stream", @"friends_birthday", […]