UNSOLVED

alanhay99

updated

10 years ago

A

alanhay99

3 Posts

0

1483

August 24th, 2016 04:00

Exception Reading File via Java APi

Can anyone advise why I get an error when attempting to read back the file saved by the code below?

Exception is at line 47 below:

exception: com.filepool.fplibrary.FPLibraryException: tag should have a blob

  @Override

  public String storeDocument(Document document) throws DocumentStoreException

  {

    String clipId = null;

    try

    {

      InputStream inputStream = document.getFile().getInputStream();

      FPClip clip = createClip();

      FPTag topTag = clip.getTopTag();

      // createDocumentAttributesTag(topTag, document);

      FPTag tag = new FPTag(topTag, "StoreContentObject");

      tag.BlobWrite(inputStream);

      clipId = clip.Write();

      inputStream.close();

      tag.Close();

      topTag.Close();

      clip.Close();

    }

    catch (Exception ex)

    {

      throw new DocumentStoreException("Error Saving Document", ex);

    }

    return clipId;

  }

  @Override

  public byte[] retrieveDocument(String id) throws DocumentStoreException

  {

    byte[] data = null;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream())

    {

      FPClip clip = new FPClip(pool, id, FPLibraryConstants.FP_OPEN_ASTREE);

      FPTag topTag = clip.getTopTag();

      // FPTag tag = topTag.getFirstChild();

      topTag.BlobRead(baos);

      //tag.BlobRead(baos);

      data = baos.toByteArray();

      if (LOGGER.isDebugEnabled())

      {

        writeDebugData(topTag);

      }

      // tag.Close();

      topTag.Close();

      clip.Close();

    }

    catch (Exception ex)

    {

      throw new DocumentStoreException("Error Retrieving Document", ex);

    }

    return data;

  }

  protected FPClip createClip() throws FPLibraryException

  {

    FPClip clip = new FPClip(pool, Long.toString(System.currentTimeMillis()));

    clip.setDescriptionAttribute("app-vendor", "xxx");

    clip.setDescriptionAttribute("app-name", "xxx");

    clip.setDescriptionAttribute("app-version", "xxx");

    clip.setRetentionPeriod(100);

    return clip;

  }