inputstream

get size of InputStream in Java

Deadly 提交于 2019-12-24 17:33:52
问题 I am trying to encrypt an InputStream which I am getting from FileItem.getInputStream(); and I want to know the encrypted stream's length. If it would be a simple FileInputStream , I could have tried File#length() or FileInputStream#getChennal().size() though not sure even those would have given me exactly what I want, but, in this case what I have is an InputStream (the encrypted one) and I want to find length of the same, I tried searching on Internet but there I could not find any

get size of InputStream in Java

寵の児 提交于 2019-12-24 17:33:06
问题 I am trying to encrypt an InputStream which I am getting from FileItem.getInputStream(); and I want to know the encrypted stream's length. If it would be a simple FileInputStream , I could have tried File#length() or FileInputStream#getChennal().size() though not sure even those would have given me exactly what I want, but, in this case what I have is an InputStream (the encrypted one) and I want to find length of the same, I tried searching on Internet but there I could not find any

Total number of rows in an InputStream (or CsvMapper) in Java

主宰稳场 提交于 2019-12-24 15:56:45
问题 How can I get the number of lines(rows) from an InputStream or from a CsvMapper without looping through and counting them? Below I have an InputStream created from a CSV file. InputStream content = (... from a resource ...); CsvMapper mapper = new CsvMapper(); mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY); MappingIterator<Object[]> it = mapper .reader(Object[].class) .readValues(content); Is it possible to do something like int totalRows = mapper.getTotalRows(); I would like to use this

How to get server message correctly

被刻印的时光 ゝ 提交于 2019-12-24 07:45:29
问题 Problem I send the message "12345" from the socket server to the client: myPrintWriter.println("12345"); After that I read this message on client: int c; while ((c = inputStream.read( )) != -1) { byte[] buffer2 = new byte[1]; buffer2[0] = (byte) c; String symbol = new String(buffer2 , "UTF-8"); String symbolCode = Integer.toString((int)buffer2[0]); Log.v(symbol, symbolCode); } Log.v("c == -1", "Disconnected"); What I see in log: With out.println("abcrefg"); Why? I think it's line termination

Why does JavaMail BodyPart.getInputStream() return an empty stream when using IMAP, but not when using POP3?

匆匆过客 提交于 2019-12-24 07:06:42
问题 I have a javax.mail application that parses through emails and gets the InputStream for all application/* attachments: private DataInputStream getAttachmentStream(Message message) throws MessagingException, IOException { if (message.isMimeType("multipart/*")) { Multipart mp = (Multipart) message.getContent(); for (int p = 0; p < mp.getCount(); p++) { BodyPart part = mp.getBodyPart(p); if (part.getContentType().toLowerCase().startsWith("application")) { InputStream is = part.getInputStream();

Java - UDP sending data over socket.. not rec. all data

僤鯓⒐⒋嵵緔 提交于 2019-12-24 03:18:32
问题 It would seem that the Client - Server application i wrote does work however it seems that not all data is processed every time. I am testing it on a local machine in Eclipse env. Server: private void sendData() throws Exception { DatagramPacket data = new DatagramPacket(outgoingData, outgoingData.length, clientAddress, clientPort); InputStream fis = new FileInputStream(responseData); int a; while((a = fis.read(outgoingData,0,512)) != -1) { serverSocket.send(data); } } Client: private void

Java - UDP sending data over socket.. not rec. all data

二次信任 提交于 2019-12-24 03:18:29
问题 It would seem that the Client - Server application i wrote does work however it seems that not all data is processed every time. I am testing it on a local machine in Eclipse env. Server: private void sendData() throws Exception { DatagramPacket data = new DatagramPacket(outgoingData, outgoingData.length, clientAddress, clientPort); InputStream fis = new FileInputStream(responseData); int a; while((a = fis.read(outgoingData,0,512)) != -1) { serverSocket.send(data); } } Client: private void

Accessing wrong raw resource in Android

天涯浪子 提交于 2019-12-23 22:55:56
问题 I have the following code. My idea is in OnCreate, I'll populate some categories from a text file in /res/raw to my database. First a tokenize the read file by lines (myCatToken), then each of these I split again to get the id and name. For some reason, instead of reading rat.txt I'm getting a totally different file and I have no idea why. The file that is actually read does exist in the /res/raw folder, however its named different. It seems that it has something to do with the resource it

Get the number of bytes of a file behind a Java InputStream

ε祈祈猫儿з 提交于 2019-12-23 19:14:13
问题 As the title says, I need to know how many bytes the file has that's "behind" an InputStream. I don't want to download all bytes and count (takes to long). I just need to know how many bytes the file has. Like this: int numberOfBytes = countBytes(inputStream); So, I need an implementation for countBytes(InputStream inputStream) 回答1: Other than by consuming the entire stream and counting the bytes, you can't (there's no API for it). There's the available() method, but it quite explicitly doesn

Which is the most efficient way of taking input in Java?

拟墨画扇 提交于 2019-12-23 18:53:37
问题 I am solving this question. This is my code: import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] t = new int[n]; int count = 0; for (int i = 0; i < n; i++) { t[i] = sc.nextInt(); if (t[i] % k == 0) { count++; } } System.out.println(count); } } But when I submit it, it get's timed out. Please help me optimize this to as much as