Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #27913

Re: RandomAccessFile and java.nio.*

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Jeff Higgins <jeff@invalid.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: RandomAccessFile and java.nio.*
Date Sun, 30 Mar 2014 22:35:19 -0400
Organization A noiseless patient Spider
Lines 36
Message-ID <lhakd2$joq$1@dont-email.me> (permalink)
References <slrnljh5m4.rhr.avl@login.logic.tuwien.ac.at>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 31 Mar 2014 02:37:22 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="6b9e92482af47766954d85fb77d372f5"; logging-data="20250"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+yhoURjSRqTULCxwFTQ+t/T6cfO42s0xw="
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10
In-Reply-To <slrnljh5m4.rhr.avl@login.logic.tuwien.ac.at>
Cancel-Lock sha1:5dJgMsJlkrY7tJne7s/p3+th6WQ=
Xref csiph.com comp.lang.java.programmer:27913

Show key headers only | View raw


On 03/30/2014 06:12 PM, Andreas Leitgeb wrote:
> As far as I understood the tutorials and documentation, then the java.io.*
> classes have been redesigned (already back in the Java 1.4 days) to work
> on the nio-API as its lower level.
>
>  From this, it's not surprising, that RandomAccessFile has a method to
> get access to the nio FileChannel and is mostly some convenience class
> that (among other things) allows reading single lines, and then have the
> current fileposition right after the newline of that read line.
>
> Unfortunately, however, the RandomAccessFile still has only constructors
> taking the open-mode as a String (with only "r","rw","rws","rwd" being the
> legal values).
>
> If instead I open a FileChannel using the nio API, then I can specify POSIX
> flags, like TRUNCATE or APPEND.
>
> What I'm missing is a way to wrap a RandomAccessFile over an existing
> FileChannel, such that I can use the more flexible open modes, but
> still get a convenient readLine().
>
> Btw., I'd really like a readLine() for reading lines also from Channels
> that are not FileChannel, but perhaps Pipe.SourceChannel or sockets.
>
> And just one more thing: I've seen that I can wrap streams like System.out
> in a Channel, using Channels.newChannel(System.out), but I don't know how
> I could undo this wrapping, eventually getting rid of the wrapping Channel
> without having System.out closed as a side effect. I'm a bit scared that
> merely "forgetting" the Channel might eventually cause it to be close()d
> from its finalizer.
>

?
LineNumberReader takes a Reader
Channels.newReader takes a ReadableByteChannel (FileChannel)

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

RandomAccessFile and java.nio.* Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-30 22:12 +0000
  Re: RandomAccessFile and java.nio.* Wayne <nospam@all.invalid> - 2014-03-30 22:24 -0400
    Re: RandomAccessFile and java.nio.* Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-31 17:54 +0000
  Re: RandomAccessFile and java.nio.* Jeff Higgins <jeff@invalid.invalid> - 2014-03-30 22:35 -0400
    Re: RandomAccessFile and java.nio.* markspace <markspace@nospam.nospam> - 2014-03-30 20:04 -0700
      Re: RandomAccessFile and java.nio.* Jeff Higgins <jeff@invalid.invalid> - 2014-03-31 02:09 -0400
        Re: RandomAccessFile and java.nio.* markspace <markspace@nospam.nospam> - 2014-03-31 00:02 -0700
          Re: RandomAccessFile and java.nio.* Jeff Higgins <jeff@invalid.invalid> - 2014-03-31 08:03 -0400
      Re: RandomAccessFile and java.nio.* Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-31 18:15 +0000
        Re: RandomAccessFile and java.nio.* Jeff Higgins <jeff@invalid.invalid> - 2014-03-31 14:38 -0400
          Re: RandomAccessFile and java.nio.* Jeff Higgins <jeff@invalid.invalid> - 2014-03-31 17:11 -0400
          Re: RandomAccessFile and java.nio.* Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-04-01 13:43 +0000
        Re: RandomAccessFile and java.nio.* markspace <markspace@nospam.nospam> - 2014-03-31 15:27 -0700
          Re: RandomAccessFile and java.nio.* Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-04-01 13:29 +0000
        Re: RandomAccessFile and java.nio.* markspace <markspace@nospam.nospam> - 2014-03-31 17:36 -0700
          Re: RandomAccessFile and java.nio.* Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-04-01 13:18 +0000

csiph-web