Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Re: Piggypack Encoding/Decoding on RandomAccessFile Date: Thu, 03 Nov 2011 16:17:07 -0700 Organization: A noiseless patient Spider Lines: 54 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 3 Nov 2011 23:16:58 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="25790"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/q9nkaDg4DE8ImNjRWe5H7" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 In-Reply-To: Cancel-Lock: sha1:97MJ7wzzg9Smw0zZ6gtuvpWWwjI= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9478 On 11/3/2011 1:52 PM, markspace wrote: > On 11/3/2011 12:50 PM, Jan Burse wrote: >> Joshua Cranmer schrieb: >>> The "standard way" (at least, all of the use cases I've ever had for >>> RandomAccessFile) effectively uses the methods that are associated with >>> java.io.DataInput to read data: read(byte[]), and read*(). >> >> I would like to use an arbirary encoding/decoding on top of the >> byte stream to get a character stream. But since RandomAccessFile >> does not implement InputStream/OutputStream, I cannot create >> a InputStreamReader/OutputStreamWrite on top. >> >> Bye >> > > 5 minutes, untested: > > > package quicktest; > > import java.io.IOException; > import java.io.InputStream; > import java.io.RandomAccessFile; > > /** > * > * @author Brenden > */ > public class RndFileStream extends InputStream { > > private final RandomAccessFile raf; > > public RndFileStream(RandomAccessFile raf) { > this.raf = raf; > } > > @Override > public int read() throws IOException { > return raf.read(); > } > > > public void seek( long pos ) throws IOException { > raf.seek(pos); > } > > } > I like that, I'm going to have to give it a try. -- Knute Johnson