mohanaki
mohanaki

Reputation: 258

Which Groovy (or Java) type to pass which supports "inputStream"?

I have a method like this.

def process(file){
  if(file != null && !file.empty){
   anotherMethod(file.inputStream);
  }
}

If I call this method from Java, what type of object do I need to pass into this method? I tried File,ZipFile but they don't have empty method.

Upvotes: 4

Views: 87

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122394

It's impossible to say for definite without seeing more context (where is this method usually called from the Grails application, for example), but a possible candidate would be MultipartFile, or rather one of its concrete implementations such as MockMultipartFile. The empty and inputStream properties that the groovy code is accessing correspond to the isEmpty() and getInputStream() bean-style accessor methods of this interface.

The normal purpose of this type is to handle multipart/form-data file uploads - it's what you get when you call request.getFile('fieldName') in a controller.

Upvotes: 1

Related Questions