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?
I am developing application called java compiler... It takes java program as input and compiles and run it, gives output. but if input program has infinite loop then how can identify and stop process execution.
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.
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
I am having trouble compiling my code for a java application that is supposed to print out the infinite series for Pi. Here is my java code:
//a java application that generates the infinite series for Pi, ie 3.14159...=4-4/3+4/5-4/7+4/9
public class Pi{ public static void main(String args[]){ //declare and initialize variables long counter=1; double pi;
[Code] ....
Here is the error in my output that results when I attempt to compile my code:
C:UsersanonymousDesktopchapter five exercises for javaPi.java:21: error: variable pi might not have been initialized total=total+pi; ^ 1 error Tool completed with exit code 1
Why do I need to initialized pi when I already initialized the total?
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.
In my card game applet I have to play some music and the user must have the ability to play, stop and pause the song using buttons. I got the play and stop to work easy but I'm unable to add the pause option/method.
I was developed a simple GUI, in that it requires modification of jtextfield content while JComboBox item selected and vice-versa. I was used itemListener on JComboBox and Document Listener on JTextField. It was gives exception while running the code. Because one listener source effected by another one..
Exceptions are like this:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Attempt to mutate in notification at javax.swing.text.AbstractDocument.writeLock(Unknown Source) at javax.swing.text.AbstractDocument.replace(Unknown Source) at javax.swing.text.JTextComponent.setText(Unknown Source) at ronanki.swing.pcahostsimUI$5.itemStateChanged(pcahostsimUI.java:368) at javax.swing.JComboBox.fireItemStateChanged(Unknown Source)
I have a swing application that gets football scores from a website using Jsoup.
When the "Get Scores" button is pressed, the scores are printed to a JTextArea with a JScrollPane.
I have also used a SwingWorker to update the scores every couple of seconds.
My problem is that every time the JTextArea updates, the JScrollPane scrolls back to the top of the text area. I wan the scroll bar to stay where the user left it.
Here is my code (The update is currently set to update every 1 second so you can see what the scroll bar is like).
import java.awt.*; import java.awt.event.*; import javax.swing.*; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class frame extends JFrame {
I wrote a program that asks the user for their letter code to tell them where they are supposed to go. I was then told to comment out asking the user and to use a loop to print each possible destination. I decided to use a for loop and am stuck in an infinite loop.
//Sam Kluender //MajorDestination.java import java.util.Scanner; public class MajorDestination { public static void main(String[] args) { char major; int countLang, countGifford; Scanner reader = new Scanner(System.in);
I just started my first programming class and I'm already playing catch up. It's a hybrid and the lectures are really short and fast paced that I don't entirely understand what is going on. I also got my textbook late (I was on the waitlist so didn't want to commit to buying early), so it's been a rough couple weeks.
Basically, I'm supposed to simulate a rental service transaction where the user will input numbers 1-4 to indicate which equipment they want to rent and input either H/h or F/f to indicate if it's for a (H)alf-day or (F)ull-day. I think I'm getting stuck in an infinite loop because every time I enter run the program to test the conditions in the loop, the console returns the "invalid choice" statement that I created in case the user inputs numbers less < 1 or > 4.
import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Scanner; public class Rental {
I've been stuck for the last couple hours trying to understand why the "printInReverse" method is getting into an infinite loop. I was supposed to make a double linked list that you can insert numbers and it orders both ascending and descending; in this case, descending is the "printInReverse" method, which takes the already ordered lists and prints it reversed, like if it was descending, and that's where the problem lives. Here follows the whole code:
I'm writing a graphical program with several Label objects. One of them is supposed to constantly change color. I tried to do it with while loop like this:
while (true) {label1.setColor(Color.blue); pause (80); label1.setColor(Color.red); pause (80);}
However, the rest of the code (after the loop) is never reached because the loop never ends. Is it possible to use infinite loop like this? And, is there any other way to handle permanent processes that are supposed to run as long as the program is running (like, in this case, blinking Label)?
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?
Its a basic program that is played by 2 people. Player one is suppose to type a number and the second player is suppose to guess the number. However after I test it out, and if I guess too low or too high I get stuck in "Your guess is too low, try again." infinite loop, what is wrong.
import java.io.*; class GuessingGame { public static void main (String[] args) throws IOException { BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in)); String firstPlayer, secondPlayer; int firstInput, secondInput; int guessCount = 0;
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());
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:
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:
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.
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....
In the code that I am currently trying to do, I want to make it so that the program loops until the randomly generated number is 1, to a maximum of 4 loops.I have figured out how to make it stop at a randomly generated 1, but I can't quite figure out how to make it stop at four loops if it doesn't reach the 1 before the maximum number of loops.
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);