Stream To Collection - Saving Results

Mar 25, 2014

I have the following

Java Code: list.stream().sorted((s, s1) -> s.getName().compareTo(s1.getName())).distinct(); mh_sh_highlight_all('java');

I want to save the results to a collection.

I saw an video tutorial on these by Oracle learning library and they mentioned an into(collection) method but I looked at the api and there isn't one.

How can I do it?

View Replies


ADVERTISEMENT

Unable To Create Audio Stream From Input Stream

Jan 18, 2015

package timerApp;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
import sun.audio.*;
import java.io.*; 
public class timerDriver
{
static int interval;

[Code]...

So I'm trying to make a program that plays an mp3 file after a timer reaches 0, but i keep receiving the error "could not create audio stream from input stream" the audio file is 3.44 MB and 00:03:45 minutes long if that's a problem

View Replies View Related

Exam Results - Code Should Split Results In Stars In 4 Categories

Nov 30, 2014

I'm doing a program where a user enters in exam results for students. Once he's entered the code, the code should split the results in stars in 4 categories.

I am working with a while loop that prints out infinite results. What I want to do is, if the user enters 2 digits, say "12", it should output 1 "*".

If the user enters "21" and "22", it should output "**".

There are 4 categories of marks which are marked with ints range1, range2, range3 and range4, which are user enter digits. Part 1 of the code is to split the user entered digits into its correct ranges. the ranges are 0-29, 30-39, 40-69 and 70-100. I've done the part where when the user enters a digit, it goes into the correct variable. After that when the user enters a digit over 100, the enter results should show up as stars. For example

Enter number =

21
22
44
66
44
23
11
111 (the 111 is where the program breaks and moves on)

So it should then display

0-29 ****

30-39

40-69 ***

70-100

Whatever I'm trying, it displays an infinite amount of stars. If I try to use break, It only outputs a single star, no matter how many digits I enter

Here is the code

int mark = 0;
int range1 = 0, range2 = 0, range3 = 0, range4 = 0;
int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
while (mark >=0 && mark <=100) {

[Code] .....

"The problem is with the while loop, the one above is something I was experimenting with "

View Replies View Related

How To Connect A Stream Via Streamers URL

May 1, 2015

soo, is there a way to (via sockets or something like that) connect to a stream via the streamers url (or just via anything) and then get the actual stream? like the images that keeps updating? so that i can display the images/stream on a jframe?

View Replies View Related

Java I/O - If Stream Contain Nothing Then Close It

Jul 10, 2014

For every stream that we create for java i/o we write at the end in finally block

finally
{
if(is!=null)
{
is.close();
}
}

It works

my question is as per syntax in if (is!=null) this means that if is means stream contain some value then close it(!=null)

then how it in my opnion it should be like (in logical way)

if stream contain nothing then close it

if(is==null)
{
is.close();
}

I am confuse about working this line

View Replies View Related

Byte Stream To String Conversion?

Apr 1, 2014

I am getting byte stream as below. These looks like UTF 8 bytes

3C524F4F543E3C535452494E473E54455354204F4E4C5920535452494E473C2F535452494E473E3C2F524F4F543E

I want java code which will convert above bytes to string as shown below

<ROOT><STRING>TEST ONLY STRING</STRING></ROOT>

View Replies View Related

Possible To Declare Two Data Input Stream?

Aug 3, 2014

I mean i need to access to two txt file at the same time so i did this in method:

DataInputStream din= new DataInputStream(FileInputStream("vip.txt"));

DataInputStream din2= new DataInputStream(FileInputStream("corporate.txt"));

But there are errors when i compile and they pointing to these two lines.

View Replies View Related

I/O / Streams :: Invalid Stream Header

Apr 12, 2004

My code runs correctly when i run the clients one after another without using threads.I am getting this following error when i run my multi-threaded server. When a server accepts a client connection, ClientHandler is the thread that handles that client.Exception in thread "main"

java.io.StreamCorruptedException: invalid stream header at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:737) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253) at comm.DOMTransfer.<init>(DOMTransfer.java:25) at ClientHandler.<init>(ClientHandler.java:18) at GridInfo.main(GridInfo.java:34)This is where the error occurs:input = new ObjectInputStream(socket.getInputStream());

View Replies View Related

Java-8 :: How To Stop Infinite Stream

May 26, 2014

I have a Stream instace which produces values using an infinite Supplier (it supplies values taken from an electronic sensor -- so unless the battery is low, the sensor will provide "for ever").

The stream is processed by a Collector using Stream.collect() (e. g. imagine that the values from the sensor should be averaged; in fact what it does is a bit more compliacted maths).

The problem is that the collector does not produce a result but hangs up, as the supplier does never stop providing more sensor values.

So what I need is a limitation rule that stops the stream. While there is a Stream.limit(long) method, it actually does not solve my problem as in my case it is not practical to stop after a particular count, while I actually want to stop streaming when the sensor value exceeds a particular limit etc. (hence, voids an arbitrary rule).
 
To sum up, what I need is Stream.limit(Predicate), i. e. the stream will stopped once the predicate becomes true.
 
Unfortunately I did not find anything like that in JRE 8.
 
Is that planned for JRE 8.1 or JRE 9.0? Or is there a known (and sophisticated) workaround?

View Replies View Related

Second XMLEncoder Silently Dies On Shared Stream?

Jul 5, 2014

My adventures with XMLEncoder continue...

I've got a simple main routine that instantiates two structurally identical classes, and attempts to write them both out to System.out with an XMLEncoder:

package xmlencoding;
import java.beans.XMLEncoder;
public class Twice {
public String name;
public static void main(String[] args)

[code]....

I expected Line 16 and Line 24 to both write some XML-formatted output, looking very similar to each other. But here's my output:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.8.0_05" class="java.beans.XMLDecoder">
<object class="xmlencoding.Twice$C1" id="Twice$C10">
<void class="xmlencoding.Twice$C1" method="getField">
<string>him</string>

[Code] ....

Now, if I change Line 24 so that the second call to writeObject is to a different stream("23. XMLEncoder e2 = new XMLEncoder(System.err);"), I do get both outputs:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.8.0_05" class="java.beans.XMLDecoder">
<object class="xmlencoding.Twice$C1" id="Twice$C10">
<void class="xmlencoding.Twice$C1" method="getField">
<string>him</string>

[code]....

So, I am inferring that this means two XMLEncoder objects can't both hold references to the same OutputStream, even if the first object is closed before the second is created. In actual practice, I guess I can live with that, since I wouldn't write the XML-encoded version of two objects to the same stream (I'd get the header twice in the same file, and I believe that's a no-no). But I am surprised that this doesn't generate some kind of exception, either when the second XMLEncoder is constructed, or when its writeObject method is called. But, it just silently dies.

View Replies View Related

VLCJ Video Stream From Server To Client

Jan 16, 2014

I am try to make an Java application using swing, to play the video from server, client can only view the video.

I am new for using Media Work in Java & using VLCJ too,

I have try by using "vlcj-master".But it showing .dll file missing error on native method..,

View Replies View Related

First Character Is Missing While Reading Input Stream

Jul 10, 2014

This is my code

// TODO Auto-generated method stub
File file=new File("D:/input.txt");
java.io.FileInputStream is=new java.io.FileInputStream(file);
int a=is.read();
try {
while((a=is.read())!=-1) {
System.out.print((char)a);

[Code] .....

My text in file is :my birthday Hello World

But in out i see only:y birthday Hello World

Why is first character is missing here?

View Replies View Related

Servlets :: Event Stream Does Not Stop After JSP Exits

Dec 5, 2014

I have a servlet which sends HTML5 server sent events to the jsp client. The servlet sends data to the client every one second. The jsp client instantiates a new eventsource and recieves the data. When the window is about to close, the jsp client closes eventsource at the "beforeunload" event (shown in the code below).

However, I have noticed that even after the client closes the eventsource and the browser exits, the server continues sending data. As far as the documentation on eventsource goes, using eventsource.close() is enough to stop client from reconnecting to the server and the server will stop sending any further push notifications.

Why the server does not stop sending push notifications even after eventsource.close() and the browser exit? Do I write any other piece of code to notify the server to stop sending data once client exits?

Pasted below are the servlet (server ) code and the client code.

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

[Code] .....

View Replies View Related

How To Get Stream Of Data From DVR And Control CCTV Camera

Jul 26, 2014

I am going to to develop an app for my final year project. basically the app is to show live video streaming on android phone from remote CCTV . The project is just in design phase i know the networking part i.e static ip for dvr etc but i dnt know how to get stream of data from dvr and how to control the CCTV camera i.e camera movement....

View Replies View Related

Swing/AWT/SWT :: Continuous Audio Data Stream Not Working

Oct 15, 2014

I am trying to make my audio loop and i tried the code below

public void audioloop() {
AudioPlayer MGP = AudioPlayer.player;
AudioStream BGM;
AudioData MD;
ContinuousAudioDataStream loop = null;
try {

[Code] ....

But is not working. I was thinking may be API is not work with java 7 because i got the following warning (AudioStream is internal proprietary API and may be removed in a future release);

View Replies View Related

Getting Class Cast Exception While Using Object Input Stream

Jun 5, 2014

I'm developing an application to track the status of a production flow-line and have hit a bit of a snag. When attempting to read saved data I run into this:

Exception in thread "main" java.lang.ClassCastException: flowline.End_Of_File cannot be cast to flowline.Operation
at flowline.Station.checkLoadPreviousStationStatus(Station.java:91)
at flowline.Station.main(Station.java:212)
Java Result: 1

I've been reading up on different methods to saving and retrieving data and have decided ObjectInputStream would be the best option.

The save method works fine, I opted to use a EndOfFile class to determine when I've reached the end of the input stream. The problem is, when my loop encounters this object, it doesn't terminate the loop.

public void checkLoadPreviousStationStatus() throws FileNotFoundException, IOException,
ClassNotFoundException, EOFException, TempArrayOutOfBoundsException{
Object loadOpn = null;
End_Of_File eof = new End_Of_File();
File f = new File(fileName);

[Code] .....

The Operation cast is a cast to the objects my LinkedList contains. The highlighted line is where the exception occurs.

View Replies View Related

Second Packet Read From Input Stream Has Incomplete Data

May 8, 2015

I a simple server that receives bytes using TCP and then saves them to a file stream.Through many tests I have seen that the first packet received is always just the filename with no other data. The second packet received only has one byte and it is the first letter of the input text file. After this all packets are sent correctly, but I can't seem to figure out what is messing up the second packet. It also appears that the last packet is written twice.

Here is an example Input/Output: [URL] .....

InputStream in = clntSock.getInputStream(); //server's input stream - gets data from the client
OutputStream out = clntSock.getOutputStream(); //server's output stream - server sends data to the client
byte[] byteBuffer = new byte[BUFSIZE];
int count = in.read(byteBuffer, 0, BUFSIZE);
String firstRead = new String(byteBuffer, 0, count);

[Code] ....

Another peculiarity to me is that the second to last packet is always just "-" and then the last packet has the remainder of the magic string which terminates the file output stream.

I am aware that it is not safe to make the assumption that the file name will be sent in one go before the loop, but I wil fix that later. I am not concerned about it at all now. THe problem si that the loop should account for any amount read in, but for some reason the first packet always contains one letter, and the second packet picks up around 16000 bytes later for some reason. Why would this be?I can't edit my above post so here is the code with code tags.

InputStream in = clntSock.getInputStream(); //server's input stream - gets data from the client
OutputStream out = clntSock.getOutputStream(); //server's output stream - server sends data to the client
byte[] byteBuffer = new byte[BUFSIZE];
int count = in.read(byteBuffer, 0, BUFSIZE);
String firstRead = new String(byteBuffer, 0, count);

[Code] ....

View Replies View Related

Java Library Function That Searches Stream Of Tcp Packets

Apr 28, 2014

i need a java library function that searches the stream of tcp packets coming to my computer from a particular ip address, so i can perform regular expressions on the contents of those packets.

View Replies View Related

Servlets :: Write Output Stream After Response Has Been Committed By Server

Aug 6, 2014

When do i get IllegalStateException in servlets.What it means by trying to write to the output stream (response) after the response has been committed by server. What it means by committing response and uncommitting response. cannot i send uncommitted response.

View Replies View Related

Servlets :: JPEG Image Upload - Data Input Stream

Jan 25, 2014

Iam trying to upload jpeg image.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

[Code] ....

In servlet the below code

DataInputStream din = new DataInputStream(request.getInputStream());
byte[] data = new byte[0];
byte[] buffer = new byte[50];
int bytesRead;
while ((bytesRead = din.read(buffer)) > 0 ) {

byte[] nData = new byte[data.length + bytesRead];
System.arraycopy(data, 0, nData, 0, data.length);
System.arraycopy(buffer, 0, nData, data.length, bytesRead);
data = newData;
}

What i see is servletinput stream does't have any values.It does't even enter while loop.

View Replies View Related

Encrypting Message Using RSA Algorithm - Invalid Stream Header Error

Jul 10, 2014

I am trying to encrypt a message using RSA algo but getting the following error:

java.io.StreamCorruptedException: invalid stream header
at java.io.ObjectInputStream.readStreamHeader(ObjectI nputStream.java:753)
at java.io.ObjectInputStream.<init>(ObjectInputStream .java:268)

Java Code :

public static final String PUBLIC_KEY_FILE = "C:/TXT.key"; 
final String originalText = "Text to be encrypted ";
ObjectInputStream inputStream = null;
FileInputStream f= new FileInputStream(PUBLIC_KEY_FILE);
// getting error on the below line
inputStream = new ObjectInputStream(f);
final PublicKey publicKey = (PublicKey) inputStream.readObject();
final byte[] cipherText = encrypt(originalText, publicKey);

View Replies View Related

How To Choose The Right Collection

Feb 14, 2015

I have small project to be implemented in Java, which, expected the management of a parking.

The project has a class abstract Vehicle, whence derive three classes: Car, Motorcycle, Heavy Vehicles; the cost estimated time for the 3 types of vehicles are: 2€ for Cars, 1€ for Motorcycle and 5€ for H.V.

In addition, in class Ticket will be stored the arrival time of the customer and the characteristics of his vehicle.

Finally, in the class Parking(which provides 80 places available), here it should be added the various types of vehicles.

Now, I though of using an Collection, as Set.. So that they can not, two Vheicle with same license plate.

View Replies View Related

String Garbage Collection

Jul 22, 2014

I have a method

void method(){
String s =null;
String s1 = new String();
}

In this all the two strings are eligible for garbage collection?

View Replies View Related

Database Driven CD Collection App

Feb 27, 2014

I am using mysql database and I have downloaded the library also I have managed to get the database connection and query working. I need to know if I need to create separate classes to add/remove/edit items and view items? Do I need to put my database connection script in every class that I create or should I create methods for both the connection and the queries that will be called in the additional classes or methods that I have?

Below is what I have written so far and it is working, I will change the database and query soon to reflect the task I need to do because I have followed a tutorial.

Java Code:

/**
* cdCollection.java
*/
package org.com.mm00422_prototype;
//Import for the SQL package
import java.sql.*;

//Registering the JDBC driver
//Class.forName("com.mysql.jdbc.Driver");

[code]....

View Replies View Related

Appropriate Way Of Populating Collection Through Instance

Feb 23, 2015

I have a method that accepts JSONArray as parameter and returns the values of it as ArrayList Object. My question which of these ways is appropriate in populating the ArrayList object this method populates the arraylist upon creation of object (I don't know what the right term to use, but as netbeans IDE suggest, JSONArray object should be final since it was used in inner class.).

private List<String> getStringList(final JSONArray jsonArr) {
return new ArrayList<String>() {
{
try {
for (int i = 0; i < jsonArr.length(); i++) {
add(jsonArr.getString(i));
}
} catch (JSONException ex) {
ex.printStackTrace();
}
}
};
}

this second method is the usual way of populating collection

private List<String> getStringList(JSONArray jsonArr) {
List<String> strList = new ArrayList<String>();
try {
for (int i = 0; i < jsonArr.length(); i++) {
strList.add(jsonArr.getString(i));
}
} catch (JSONException ex) {
ex.printStackTrace();
}
}

What are the advantages and disadvantages between the two? like which is faster? or which consumed larger memory?

View Replies View Related

Garbage Collection Logs In Application

Nov 26, 2013

In my applications garbage collection logs, I see below line.

2013-11-26T10:35:45.050-0500: 5195.298: [GC 5195.298: [DefNew: 17430K->456K(19136K), 0.0102408 secs] 796185K->779211K(2668480K), 0.0103687 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
2013-11-26T10:36:10.593-0500: 5220.840: [GC 5220.840: [DefNew: 17480K->398K(19136K), 0.0100548 secs] 796235K->779153K(2668480K), 0.0101835 secs]

The last line seems half cut. Does that indicate that there is memory leak in my application? I have not seen the app throwing the out of memory error.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved