• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How can I read file in FileSystem with the FIFO principle ?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello  dear Rancher,
I receive a stream of Data each seconde and store it in a Filesystem. Please how can I read this Data with the FIFO principle  ?

Thanks!

 
Marshal
Posts: 79961
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Have you seen the Java™ Tutorials section about NIO?
Please explain how these data are stored. Are they received as some sort of input stream, or are they written directly to a file? Does your input write them sequentially into your file?
 
Saloon Keeper
Posts: 15727
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're asking how to store a stack in a file, you can do this easily by keeping the offset of the last entry in the file header, and in every entry keep the offset of the previous entry.

It goes roughly like this:
 
Cass Ted
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank    
The data  are written directly to  a file
 
Campbell Ritchie
Marshal
Posts: 79961
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephan: wouldn't a stack be LIFO/FILO and OP asked for FIFO?
Presumably you can write successive lines to a file and read them in order. But that produces a race condition, so it wouldn't be thread‑safe. It might also not be possible to open a file for reading and writing simultaneously.
 
Stephan van Hulst
Saloon Keeper
Posts: 15727
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahhh yes. For some reason I read LIFO and I just went with it.

FIFO is indeed just writing the entries one after the other. I have no idea why one would want to read and write at the same time, maybe OP can share more details about their use case with us.
 
Rancher
Posts: 326
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Campbell I had to look it up as I also get confused from time to time - but you're correct:

FIFO: Queue - what comes in first gets served back first
LIFO: Stack - what comes in last gets served back first
 
Campbell Ritchie
Marshal
Posts: 79961
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But you can easily use a list as a FIFO collection.
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic