inputstream

How to write numbers to a file and make them readable between Java and C#

时光怂恿深爱的人放手 提交于 2019-12-25 04:28:24
问题 I'm into a "compatibility" issue between two versions of the same program, the first one written in Java, the second it's a port in C#. My goal is to write some data to a file (for example, in Java), like a sequence of numbers, then to have the ability to read it in C#. Obviously, the operation should work in the reversed order. For example, I want to write 3 numbers in sequence, represented with the following schema: first number as one 'byte' (4 bit) second number as one 'integer' (32 bit)

Android: decode bitmap from stream

跟風遠走 提交于 2019-12-25 04:11:43
问题 I have this code to get bitmaps from the user external storage /** * Get bitmap from input stream * @param is * @param reqWidth * @param reqHeight * @return Bitmap */ public static Bitmap decodeSampleBitmapFromStream(InputStream is, int reqWidth, int reqHeight) { BufferedInputStream bis = new BufferedInputStream(is); // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;

Android InputStream.read() horribly slow

夙愿已清 提交于 2019-12-25 02:55:38
问题 I'm working on an Android app that needs to communicate with a server (running on my PC) which is also written by me. The problem is that InputStream.read() takes an eternity, processing 200kb takes something around 30 seconds. Maybe the garbage collection is involved somehow, during my loop it gets called from time to time but the listed delays are only 2 or 3 millisecods and all in all maybe 20ms so I don't think that's the problem. My code: client = new Socket("192.168.1.1", 1235); client

Android: 2 threads listening on the same socket

早过忘川 提交于 2019-12-25 02:53:55
问题 Situation : A client communicates to a server via a single socket connection. The Client can randomly send serialized objects, or just simple parameters, the the server. Problem : How to make the server simultaneously listen for ObjectInputStream and InputStream from the Client ? What I'm thinking of: A 'master' thread spawns 2 child Threads. One child listens to ObjectInputStreams from the client, and the other child listens to InputStreams. Will this approach work ? Because I've heard

Multiple HttpURLConnection calls for get throwing Premature end of file exception with InputStream

给你一囗甜甜゛ 提交于 2019-12-25 01:58:17
问题 I'm trying to make multiple calls to a REST API using HttpURLConnection with GET method and retrieving the response through InputStream. It worked fine previously for 3 months but now it's throwing below exception: SAXException Occurred during getArtifactsUrl method:: org.xml.sax.SAXParseException; Premature end of file. at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) [xercesImpl.jar:6.1.0.Final] at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) [xercesImpl.jar

How to improve performance of deserializing objects from HttpsURLConnection.getInputStream()?

依然范特西╮ 提交于 2019-12-25 01:45:39
问题 I have a client-server application where the server sends some binary data to the client and the client has to deserialize objects from that byte stream according to a custom binary format. The data is sent via an HTTPS connection and the client uses HttpsURLConnection.getInputStream() to read it. I implemented a DataDeserializer that takes an InputStream and deserializes it completely. It works in a way that it performs multiple inputStream.read(buffer) calls with small buffers (usually less

How to load streamed data directly into a BufferedImage

跟風遠走 提交于 2019-12-25 00:18:55
问题 I am using the code provided by this accepted answer to send a list of files over a socket in Java. My goal is to be receiving a list of images. What I would like to do is read these images directly into memory as BufferedImages before writing them to disk. However, my first attempts, which was to use ImageIO.read(bis) (again, see the attached question) failed, as it attempted to continue reading beyond the end of the first image file. My current idea is to write the data from the socket to a

Why can't I seem to read an entire compressed file from a URL stream?

♀尐吖头ヾ 提交于 2019-12-24 22:53:19
问题 I'm trying to parse Wiktionary dumps on the fly, directly from the URL, in Java. The Wiki dumps are distributed as compressed BZIP2 files, and I am using the following approach to attempt to parse them: String fileURL = "https://dumps.wikimedia.org/cswiktionary/20171120/cswiktionary-20171120-pages-articles-multistream.xml.bz2"; URL bz2 = new URL(fileURL); BufferedInputStream bis = new BufferedInputStream(bz2.openStream()); CompressorInputStream input = new CompressorStreamFactory()

Output from Process.getInputStream() buffered too long

自古美人都是妖i 提交于 2019-12-24 22:10:04
问题 I have a Java program that uses Process Builder to start an external program. I have a Process Builder with the command, and I use the code below to get the program going. What I want to do is to print out the output just as the external program would have done, and I try to do this with the following code: pb.redirectErrorStream(true); p = pb.start(); InputStream is = p.getInputStream(); InputStreamReader isr = new inputStreamReader(is); BufferedReader br = new BufferedReader(isr, 32); while

cannot resolve getAssets() method

余生长醉 提交于 2019-12-24 19:01:38
问题 hi i have been having trouble with the getAsset() method. i trying to get a xml file from the assets folder with the getAsset() to be put into a inputStream. CODE: public class MainActivity extends AppCompatActivity { List people; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { InputStream is = getAssets().open("people.xml"); people = XMLParser.readPeople(is); }catch (IOException e){ e