public long putStreamOptimizedDisk(String filePath,InputStream inputStream) throws IOException, VmdkFormatException {
  StreamVmdkReader disk=getStreamVmdkReader(inputStream);
  DiskWriter writer=null;
  try {
    writer=putDisk(filePath,disk.getAdapterType(),disk.getCapacityInSectors());
    writer.writeDdb(disk.getDdb());
    byte[] grain=new byte[disk.getGrainSize() * SparseUtil.DISKLIB_SECTOR_SIZE];
    int grainSize=disk.getNextGrain(grain);
    int grainCount=0;
    while (grainSize >= 0) {
      grainCount++;
      if (0 == (grainCount % 1000)) {
        logger.debug("NfcClient putStreamOptimizedDisk for file {} preparing to write grain count/size {}/{}",filePath,grainCount,grainSize);
      }
      if (grainSize > 0) {
        long lba=disk.getCurrentLba();
        for (int offset=0; offset < grainSize; offset+=SparseUtil.DISKLIB_SECTOR_SIZE) {
          writer.writeGrain(lba++,grain,offset);
        }
      }
      grainSize=disk.getNextGrain(grain);
    }
    logger.debug("NfcClient putStreamOptimizedDisk for file {} write complete on grain count/size {}/{}",filePath,grainCount,grainSize);
    writer.finalizeWrite();
    close();
    return disk.getCapacityInSectors() * SparseUtil.DISKLIB_SECTOR_SIZE;
  }
 catch (  SocketException e) {
    logger.error("Remote host closed connection while uploading to datastore (could be of out of space): {}",e);
    throw e;
  }
 finally {
    if (writer != null) {
      writer.close();
    }
    abort();
  }
}

public long putStreamOptimizedDisk ( String filePath , InputStream inputStream ) throws IOException , VmdkFormatException { StreamVmdkReader disk = getStreamVmdkReader ( inputStream ) ; DiskWriter writer = null ; try { writer = putDisk ( filePath , disk . getAdapterType ( ) , disk . getCapacityInSectors ( ) ) ; writer . writeDdb ( disk . getDdb ( ) ) ; byte [ ] grain = new byte [ disk . getGrainSize ( ) * SparseUtil . DISKLIB_SECTOR_SIZE ] ; int grainSize = disk . getNextGrain ( grain ) ; int grainCount = 0 ; while ( grainSize >= 0 ) { grainCount ++ ; if ( 0 == ( grainCount % 1000 ) ) { logger . debug ( "NfcClient putStreamOptimizedDisk for file {} preparing to write grain count/size {}/{}" , filePath , grainCount , grainSize ) ; } if ( grainSize > 0 ) { long lba = disk . getCurrentLba ( ) ; for ( int offset = 0 ; offset < grainSize ; offset += SparseUtil . DISKLIB_SECTOR_SIZE ) { writer . writeGrain ( lba ++ , grain , offset ) ; } } grainSize = disk . getNextGrain ( grain ) ; } logger . debug ( "NfcClient putStreamOptimizedDisk for file {} write complete on grain count/size {}/{}" , filePath , grainCount , grainSize ) ; writer . finalizeWrite ( ) ; close ( ) ; return disk . getCapacityInSectors ( ) * SparseUtil . DISKLIB_SECTOR_SIZE ; } catch ( SocketException e ) { logger . error ( "Remote host closed connection while uploading to datastore (could be of out of space): {}" , e ) ; throw e ; } finally { if ( writer != null ) { writer . close ( ) ; } abort ( ) ; } }
upload image to remote datastore as a disk . if the image name exists in the datastore , it will be overwritten . the only disk type than can be correctly uploaded in this mode is streamoptimized . < p / > adapted from : https : / / opengrok . eng . vmware . com / source / xref / vdc - 2015 . perforce - shark . 1700 / vdc - 2015 / src / transfer - svc / ts - main / src / main / java / com / vmware / transfer / impl / nfcendpointimpl . java
