Forum Discussion

Stalsy's avatar
Stalsy
Contributor
3 years ago

Error when referencing java.util.stream

I'm trying to write some code to process One-Time-Passwords using APIs. I have to read the SMSs as a Stream so I "import java.util.stream" but I get a compilation error "unable to resolve class java.util.stream".

If I "import java.util.*" then the compilation error moves to line 14 where I define the Stream: "unable to resolve class Stream @ line 14, column 1. def private Stream getMessages() { ^"

Java docs say that java.util.stream has been around since java 1.8

Code sample:

import com.twilio.*

import java.util.*;

import com.twilio.*

import com.twilio.base.*

import javax.jms.Message;

//import java.util.*; //uncommented gives error at line 14 -see below

import java.util.stream //compile error: "unable to resolve class java.util.stream" ;

def public static String getMessage() {

return getMessages().filter(m -> m.getDirection().compareTo(Message.Direction.INBOUND) == 0)

.filter(m -> m.getTo().equals("+61999999")).map(Message::getBody).findFirst()

.orElseThrow(IllegalStateException::new); }

 

def private Stream getMessages() {            //line 14

ResourceSet messages = Message.reader(SID).read();

return StreamSupport.stream(messages.spliterator(),false);

}

 

String SID="xxxxxx..."

String AUTH_TOKEN= "yyyyyy...."