Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.collabnet.ce.webservices;
  
  import  com.collabnet.ce.soap50.webservices.ClientSoapStubFactory;
  
  import  com.collabnet.ce.soap50.webservices.filestorage.ISimpleFileStorageAppSoap;
  
  import java.io.File;
Class to hold the file-related methods. Wraps a collabNetApp.
 
 public class SimpleFileStorageApp {
     private static int BYTE_SIZE = 1048576; // 1 MB
     private CollabNetApp collabNetApp;
     private ISimpleFileStorageAppSoap ifsa;
    
    
Construct a new SimpleFileStorageApp.

Parameters:
collabNetApp a valid (logged-in) collabNetApp.
 
     public SimpleFileStorageApp(CollabNetApp collabNetApp) {
         this. = collabNetApp;
         this. = this.getISimpleFileStorageAppSoap();
     }
    
    

Returns:
a Client Soap stub for the SimpleFileStorageApp.
 
     private ISimpleFileStorageAppSoap getISimpleFileStorageAppSoap() {
         String soapURL = this.getUrl() + . +
             "SimpleFileStorageApp?wsdl";
         return (ISimpleFileStorageAppSoap) ClientSoapStubFactory.
             getSoapStub(ISimpleFileStorageAppSoap.classsoapURL);
     }
    
    
Upload a file to the server.

Parameters:
file to upload.
Returns:
the fileId associatd with the uploaded file.
Throws:
RemoteException.
 
     public String uploadFile(File filethrows RemoteException {
         String id = null;    
         byte[] bytes = new byte[.];
         byte[] smallerBytes = null;
         int bytesRead = 0;
         FileInputStream istream = null;
         try {
             istream = new FileInputStream(file);
         } catch (FileNotFoundException fnfe) {
             throw new CollabNetApp.
                 CollabNetAppException("uploadBuildLog failed due to " +
                                       "FileNotFoundException: " + 
                                       fnfe.getMessage());
         }
         try {
             id = this..startFileUpload(this.getSessionId());
             while ((bytesRead = istream.read(bytes)) > 0) {
                 /* ifsa.write doesn't manage the byte array size as
                  * separate data, so it will write the entire array,
                  * no matter how big.  So we check if the real data is
                  * smaller, and in that case, copy to a smaller array.
                  */
                 if (bytesRead == .) {
                     this..write(this.getSessionId(), idbytes);
                 } else {
                     smallerBytes = new byte[bytesRead];
                     System.arraycopy(bytes, 0, smallerBytes, 0, bytesRead);
                     this..write(this.getSessionId(), idsmallerBytes);
                 }
             }
             this..endFileUpload(this.getSessionId(), id);
             istream.close();
         } catch (IOException ioe) { 
             throw new CollabNetApp.
                 CollabNetAppException("uploadBuildLog failed due to " +
                                       "IOException: " + ioe.getMessage());
         }
         return id;
     } 
    
    
    
Below are wrapping functions, to make the code neater and in case, something changes. /
 
 
     private void checkValidSessionId() {
         this..checkValidSessionId();
     }
     
     private String getSessionId() {
        return this..getSessionId();
    }
    
    private String getUrl() {
        return this..getServerUrl();
    }
New to GrepCode? Check out our FAQ X