Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Wrap QueueFile around an existing File? #199

Open
bhavadeepk opened this issue Sep 21, 2018 · 6 comments
Open

Wrap QueueFile around an existing File? #199

bhavadeepk opened this issue Sep 21, 2018 · 6 comments

Comments

@bhavadeepk
Copy link

bhavadeepk commented Sep 21, 2018

From Javadocs,

// A persistent ObjectQueue.
ObjectQueue<String> queue = ObjectQueue.create(queueFile, converter);

I have some messages to be sent to a server from custom android devices in FIFO order. If the device is rebooted before all the messages in the queue are successfully sent, the remainder is persisted in the File I wrapped the queueFile with.
But I cannot import this existing file into a new instance(after reboot) of the QueueFile unless I delete the file. #125 which loses the messages stacked before shutdown.

How can I persist the queue across reboots using this library?

Let me know if you have any questions. Thanks

@JakeWharton
Copy link
Collaborator

This should work out of the box. What exception do you get when you try to load the queue after reboot?

@bhavadeepk
Copy link
Author

bhavadeepk commented Sep 23, 2018

When I use, in my onCreate() or BootUpReceiver,

File file = // ...
QueueFile queueFile = new QueueFile.Builder(file).build();

I end up with EOFException unless I perform file.delete() operation.

@himanshusahay
Copy link

I'm facing the same issue where I end up with an EOF exception unless I delete the underlying file. Is there a resolution here?

@steveperkins
Copy link

I'm seeing the same problem as well. My purpose for using this library is to persist data locally and read it back in after an unexpected shutdown, but I I just get EOFException when trying to access the existing file (even if it's zero bytes).

@steveperkins
Copy link

I think core issue for me is that the example is unclear as to what
// File...
represents. I took it to mean I'm responsible for creating the queue file and providing that to QueueFile. This results in a 0-byte file ready for input. However, QueueFile(File) assumes the file will always either not exist or already have the requisite header, which causes the EOFException.

I'd think QueueFile would check the length of available bytes in the stream before attempting to read in the header (and if length is 0 bytes, just create the header), but apparently not.

My solution was to ignore the reference in the example and just use:
QueueFile queueFile = new QueueFile.Builder(new File("fileThatWillBeCreatedIfNecessary.queue")).build();

If I have some time to dig deeper into the source I'll submit a PR.

@ehartford
Copy link

I have the same problem. Is there a workaround?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants