inputstream

How to skip invalid characters in stream in Java/Scala?

别说谁变了你拦得住时间么 提交于 2019-12-20 09:54:05
问题 For example I have following code Source.fromFile(new File( path), "UTF-8").getLines() and it throws exception Exception in thread "main" java.nio.charset.MalformedInputException: Input length = 1 at java.nio.charset.CoderResult.throwException(CoderResult.java:260) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:319) I don't care if some lines were not read, but how to skip invalid chars and continue reading lines? 回答1: You can influence the way that the charset decoding handles

Reading single InputStream from multiple methods

亡梦爱人 提交于 2019-12-20 07:09:06
问题 I have initialized an InputStream in a single method in a class and passing it to next method for processing. The InputStream essentially encapsulates CSV file for processing. Another method calls 2 different methods passing in same InputStream one for retrieving headers and another for processing contents. The structure looks something as given below: main() { FileInputStream fis = new FileInputStream("FileName.CSV"); BufferedInputStream bis = new BufferedInputStream(fis); InputStreamReader

inputstream is closed error while uploading zip file through jsch to sftp site

心不动则不痛 提交于 2019-12-20 06:32:23
问题 While uploading a zip file to SFTP, we are getting the below error. The same code is working fine for another application. We are using jsch-0.1.44.jar for SFTP connection. java.io.IOException: inputstream is closed at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:571) at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:431) at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:398) aused by: java.io.IOException: inputstream is closed at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java

Receive Floats using java sockets from C++

删除回忆录丶 提交于 2019-12-20 06:09:51
问题 I need to receive an array or a class containing floats from a c++ client to java server using sockets. But the InputStreamReader is not getting it right. Any reasons. Any suggestions for simpler ways would be appreciated. Thanks. Java Server Code public static void main(String[] args) throws IOException { // TODO code application logic here Values values=new Values(); gui display=new gui(); display.setVisible(true); ServerSocket Sock=new ServerSocket(9090); try{ while(true){ System.out

Sonar violation: “Method may fail to close stream on exception”

我是研究僧i 提交于 2019-12-20 06:03:07
问题 I have this method: private void unZipElementsTo(String inputZipFileName, String destPath) throws FileNotFoundException, IOException { OutputStream out = null; InputStream in = null; ZipFile zf = null; try { zf = new ZipFile(inputZipFileName); for (Enumeration<? extends ZipEntry> em = zf.entries(); em.hasMoreElements();) { ZipEntry entry = em.nextElement(); String targetFile = destPath + FILE_SEPARATOR + entry.toString().replace("/", FILE_SEPARATOR); File temp = new File(targetFile); if (

Sonar violation: “Method may fail to close stream on exception”

眉间皱痕 提交于 2019-12-20 06:02:04
问题 I have this method: private void unZipElementsTo(String inputZipFileName, String destPath) throws FileNotFoundException, IOException { OutputStream out = null; InputStream in = null; ZipFile zf = null; try { zf = new ZipFile(inputZipFileName); for (Enumeration<? extends ZipEntry> em = zf.entries(); em.hasMoreElements();) { ZipEntry entry = em.nextElement(); String targetFile = destPath + FILE_SEPARATOR + entry.toString().replace("/", FILE_SEPARATOR); File temp = new File(targetFile); if (

Application hangs when attempting to retrieve text from an inputstream

无人久伴 提交于 2019-12-20 05:47:19
问题 Situation I've been creating a program to exchange messages between two computers in the LAN. One computer identifies itself as the server while the other is a client. Upon startup, the user has to enter the Host and the Port of another computer, should he wish to connect as a client to that machine. The setup of how it works is very basic: You type your message, hit enter and it shows up on your own screen. After that your conversation partner has to click a button to retrieve the latest

Read exactly n bytes from InputStream in Swift 4

烈酒焚心 提交于 2019-12-20 05:18:04
问题 I have a server that sends me messages over TCP where the first 4 bytes determine the length of the rest of the message. So I need to 1) read 4 bytes into an UInt32 (works) and store it into bytes_expected 2) read bytes_expected bytes into message Right now my code looks like this: private let inputStreamAccessQueue = DispatchQueue(label: "SynchronizedInputStreamAccess") func inputStreamHandler(_ event: Stream.Event) { switch event { case Stream.Event.hasBytesAvailable: self.handleInput() ...

Why does Mule FTP connector doesn't delete file when streaming is enabled

霸气de小男生 提交于 2019-12-20 04:38:24
问题 This is the relevant part of my mule-config <ftp:connector name="ftp.connector" streaming="true"/> <flow name="ftp2file"> <ftp:inbound-endpoint connector-ref="ftp.connector" host="xxx" port="21" path="/path" user="test" password="test"/> <file:outbound-endpoint path="/newPath" outputPattern="#[header:originalFilename]"/> </flow> Files on FTP server gets deleted when streaming is disabled but files stays on in my case when streaming is enabled. I've 2 questions: Why is behavior internally

Android TCP app hanging on inStream.readline()

∥☆過路亽.° 提交于 2019-12-20 03:25:08
问题 This is a continuation of this question because it my orginal question was answered, but it did not solve the bug. Question: How do I fix the code hanging on this line inStream.readline() My Intent: This is in a thread that will loop through checking if there is an outMessage, if there is, it will send the message. Next it will check it if there is anything in the in-stream, if there is, it will send it to the handler in my main activity. Lastly, it will sleep for 1 second, then check again.