コード例 #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 void addContentLocationForDataBean(DataBean bean, StorageMethod method, URL url)
     throws ContentLengthException, IOException {
   ContentLocation location = new ContentLocation(method, getHandlerFor(method), url);
   try {
     setOrVerifyContentLength(bean, getContentLength(location));
   } catch (IOException e) {
     throw new IOException("content length not available: " + e);
   } catch (ContentLengthException e) {
     try {
       DataManager manager = Session.getSession().getDataManager();
       String msg;
       msg =
           "Wrong content length for dataset "
               + bean.getName()
               + ". "
               + " In ContentLocation "
               + location.getUrl()
               + ", length is "
               + getContentLength(location)
               + " bytes. ";
       msg += "Content locations: ";
       for (ContentLocation loc : manager.getContentLocationsForDataBeanSaving(bean)) {
         msg += loc.getUrl() + " " + manager.getContentLength(loc) + " bytes, ";
       }
       throw new ContentLengthException(msg);
     } catch (IOException e1) {
       logger.error("another exception while handling " + Exceptions.getStackTrace(e), e);
     }
   }
   bean.addContentLocation(location);
 }
コード例 #3
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);
  }
コード例 #4
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);
  }
コード例 #5
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);
    }
  }
コード例 #6
0
  public int compare(final ContentLocation a, final ContentLocation b) {
    if (a == b) {
      return 0;
    }

    final int siteNameCompare = a.getSiteName().compareTo(b.getSiteName());
    if (siteNameCompare != 0) {
      return siteNameCompare;
    }

    final MenuItemEntity menuitemA = a.getMenuItem();
    final MenuItemEntity menuitemB = b.getMenuItem();

    final int menuitemALevel = menuitemA.getLevel();
    final int menuitemBLevel = menuitemB.getLevel();
    if (menuitemALevel < menuitemBLevel) {
      return -1;
    } else if (menuitemALevel > menuitemBLevel) {
      return 1;
    }

    // at this point save levels...compare each level
    List<MenuItemEntity> menuitemAPath = menuitemA.getMenuItemPath();
    List<MenuItemEntity> menuitemBPath = menuitemB.getMenuItemPath();

    for (int i = 0; i < menuitemAPath.size(); i++) {
      final MenuItemEntity currentALevel = menuitemAPath.get(i);
      final MenuItemEntity currentBLevel = menuitemBPath.get(i);
      final int currentLevelCompare = currentALevel.getName().compareTo(currentBLevel.getName());
      if (currentLevelCompare != 0) {
        return currentLevelCompare;
      }
    }

    // at this point they are completely equal, according to this comparator
    return 0;
  }
コード例 #7
0
ファイル: DataManager.java プロジェクト: Linhua-Sun/chipster
 public Long getContentLength(ContentLocation location) throws IOException {
   return location.getHandler().getContentLength(location);
 }
コード例 #8
0
ファイル: DataManager.java プロジェクト: Linhua-Sun/chipster
 private boolean isAccessible(ContentLocation location) {
   return location.getHandler().isAccessible(location);
 }