コード例 #1
0
ファイル: DataManager.java プロジェクト: Linhua-Sun/chipster
  public OutputStream getContentOutputStreamAndLockDataBean(DataBean bean) throws IOException {

    // only local temp beans support output, so convert to local temp bean if needed
    ContentLocation tempLocalLocation = bean.getContentLocation(StorageMethod.LOCAL_TEMP);
    if (tempLocalLocation == null) {
      this.convertToLocalTempDataBean(bean);
      tempLocalLocation = bean.getContentLocation(StorageMethod.LOCAL_TEMP);
    }

    // remove all other locations, as they will become obsolete when OutputStream is written to
    while (bean.getContentLocations().size() > 1) {
      for (ContentLocation location : bean.getContentLocations()) {
        if (location != tempLocalLocation) {
          bean.removeContentLocation(location);
          break; // remove outside of the iterator, cannot continue
        }
      }
    }

    // change data id
    bean.setId(CryptoKey.generateRandom());
    bean.setChecksum(null);
    bean.setSize(null);

    return tempLocalLocation.getHandler().getOutputStream(tempLocalLocation);
  }
コード例 #2
0
ファイル: DataManager.java プロジェクト: Linhua-Sun/chipster
  public File getLocalFile(DataBean bean) throws IOException {

    ContentLocation location = bean.getContentLocation(StorageMethod.LOCAL_FILE_METHODS);

    // convert non local file beans to local file beans
    if (location == null) {
      this.convertToLocalTempDataBean(bean);
      location = bean.getContentLocation(StorageMethod.LOCAL_FILE_METHODS);
    }

    // get the file
    LocalFileContentHandler handler = (LocalFileContentHandler) location.getHandler();
    return handler.getFile(location);
  }
コード例 #3
0
ファイル: DataManager.java プロジェクト: Linhua-Sun/chipster
  /**
   * Get a local file with random access support, in practice a temp file. If random access support
   * isn't really needed, please use method getLocalFile().
   *
   * @param bean
   * @return
   * @throws IOException
   */
  public File getLocalRandomAccessFile(DataBean bean) throws IOException {

    // Check if there is a suitable location already
    ContentLocation location = getClosestRandomAccessContentLocation(bean);
    if (location == null || !location.getMethod().isLocal()) {
      // Closest random access location isn't local, make a local copy (temp files do support random
      // access)
      this.convertToLocalTempDataBean(bean);
    }

    // Now this is a local random access copy
    location = getClosestRandomAccessContentLocation(bean);

    // get the file
    LocalFileContentHandler handler = (LocalFileContentHandler) location.getHandler();
    return handler.getFile(location);
  }
コード例 #4
0
ファイル: DataManager.java プロジェクト: Linhua-Sun/chipster
  private InputStream getBaseContentStream(DataBean bean, DataNotAvailableHandling naHandling)
      throws IOException {

    // try local content locations first
    ContentLocation location = getClosestContentLocation(bean);

    if (location != null) {

      // local available TODO maybe check if it really is available
      return location.getHandler().getInputStream(location);
    }

    // try from filebroker
    Exception remoteException;
    try {
      return Session.getSession()
          .getServiceAccessor()
          .getFileBrokerClient()
          .getInputStream(bean.getId());
    } catch (Exception e) {
      remoteException = e;
    }

    // not available
    switch (naHandling) {
      case EMPTY_ON_NA:
        return new ByteArrayInputStream(new byte[] {});

      case INFOTEXT_ON_NA:
        return new ByteArrayInputStream(DATA_NA_INFOTEXT.getBytes());

      case NULL_ON_NA:
        return null;

      default:
        String message = "data contents not available";
        if (remoteException != null) {
          message += ": " + remoteException.getMessage();
        }
        throw new RuntimeException(message, remoteException);
    }
  }
コード例 #5
0
ファイル: DataManager.java プロジェクト: Linhua-Sun/chipster
 public Long getContentLength(ContentLocation location) throws IOException {
   return location.getHandler().getContentLength(location);
 }
コード例 #6
0
ファイル: DataManager.java プロジェクト: Linhua-Sun/chipster
 private boolean isAccessible(ContentLocation location) {
   return location.getHandler().isAccessible(location);
 }