Start a Conversation

Unsolved

This post is more than 5 years old

1446

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;

  }

208 Posts

August 24th, 2016 06:00

Hi Alan -

It looks like you are trying to read from the top tag, where you actually created a child tag called 'StoreContentObject' (line 13) which is where your blob is attached.  You can use FPTag.getFirstChild() on the top tag instance to navigate to your blob tag in tree mode.

Good Luck,

Mike Horgan

3 Posts

August 25th, 2016 07:00

Thanks Mike however I get the same exception from the child tag. Essentially, regardless of whether I swap the commented lines in the source posted I get the same exception.

No Events found!

Top