Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6e3325a799d576817b61fd7f3c037ec989584532 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package org.eclipse.osee.ote.rest.client.internal;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URI;

import javax.ws.rs.core.MediaType;

import org.eclipse.osee.ote.rest.client.Progress;

import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;

public class GetOteServerFile extends BaseClientCallable<Progress> {

   private URI uri;
   private String filePath;
   @SuppressWarnings("unused")
   private Progress progress;
   private WebResourceFactory factory;
   private File destination;
   
   public GetOteServerFile(URI uri, File destination, String filePath, Progress progress, WebResourceFactory factory) {
      super(progress);
      this.uri = uri;
      this.filePath = filePath;
      this.progress = progress;
      this.factory = factory;
      this.destination = destination;
   }

   @Override
   public void doWork() throws Exception {
      WebResource client = factory.createResource(uri);
      ClientResponse response = client.queryParam("path", filePath).path("ote").path("file").accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
      if(response.getStatus() == ClientResponse.Status.OK.getStatusCode()){
         InputStream is = response.getEntityInputStream();
         FileOutputStream fos = new FileOutputStream(destination);
         byte[] data = new byte[2048];
         int numRead = 0;
         while((numRead = is.read(data)) != -1){
            fos.write(data, 0, numRead);
         }
         fos.flush();
         fos.close();
      } else {
         throw new Exception(response.toString());
      }
   }

}

Back to the top