diff options
author | Björn Stenberg <bjorn@haxx.se> | 2007-01-08 23:53:00 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2007-01-08 23:53:00 +0000 |
commit | 7039a05147b8bbfc829babea1c65bd436450b505 (patch) | |
tree | 4ba555eb84ed97b72b0575034d5b0530a393713e /songdbj/net/shredzone/ifish/ltr/OggFastFileStream.java | |
parent | 6d4c19707ef95942e323cbdc89fbbfdbe45e7cc5 (diff) | |
download | rockbox-7039a05147b8bbfc829babea1c65bd436450b505.tar.gz rockbox-7039a05147b8bbfc829babea1c65bd436450b505.zip |
Splitting out songdbj
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11953 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'songdbj/net/shredzone/ifish/ltr/OggFastFileStream.java')
-rw-r--r-- | songdbj/net/shredzone/ifish/ltr/OggFastFileStream.java | 249 |
1 files changed, 0 insertions, 249 deletions
diff --git a/songdbj/net/shredzone/ifish/ltr/OggFastFileStream.java b/songdbj/net/shredzone/ifish/ltr/OggFastFileStream.java deleted file mode 100644 index f86699b0f1..0000000000 --- a/songdbj/net/shredzone/ifish/ltr/OggFastFileStream.java +++ /dev/null | |||
@@ -1,249 +0,0 @@ | |||
1 | /* | ||
2 | * iFish -- An iRiver iHP jukebox database creation tool | ||
3 | * | ||
4 | * Copyright (c) 2004 Richard "Shred" Körber | ||
5 | * http://www.shredzone.net/go/ifish | ||
6 | * | ||
7 | *----------------------------------------------------------------------- | ||
8 | * ***** BEGIN LICENSE BLOCK ***** | ||
9 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | ||
10 | * | ||
11 | * The contents of this file are subject to the Mozilla Public License Version | ||
12 | * 1.1 (the "License"); you may not use this file except in compliance with | ||
13 | * the License. You may obtain a copy of the License at | ||
14 | * http://www.mozilla.org/MPL/ | ||
15 | * | ||
16 | * Software distributed under the License is distributed on an "AS IS" basis, | ||
17 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
18 | * for the specific language governing rights and limitations under the | ||
19 | * License. | ||
20 | * | ||
21 | * The Original Code is IFISH. | ||
22 | * | ||
23 | * The Initial Developer of the Original Code is | ||
24 | * Richard "Shred" Körber. | ||
25 | * Portions created by the Initial Developer are Copyright (C) 2004 | ||
26 | * the Initial Developer. All Rights Reserved. | ||
27 | * | ||
28 | * Contributor(s): | ||
29 | * | ||
30 | * Alternatively, the contents of this file may be used under the terms of | ||
31 | * either the GNU General Public License Version 2 or later (the "GPL"), or | ||
32 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
33 | * in which case the provisions of the GPL or the LGPL are applicable instead | ||
34 | * of those above. If you wish to allow use of your version of this file only | ||
35 | * under the terms of either the GPL or the LGPL, and not to allow others to | ||
36 | * use your version of this file under the terms of the MPL, indicate your | ||
37 | * decision by deleting the provisions above and replace them with the notice | ||
38 | * and other provisions required by the GPL or the LGPL. If you do not delete | ||
39 | * the provisions above, a recipient may use your version of this file under | ||
40 | * the terms of any one of the MPL, the GPL or the LGPL. | ||
41 | * | ||
42 | * ***** END LICENSE BLOCK ***** | ||
43 | */ | ||
44 | |||
45 | package net.shredzone.ifish.ltr; | ||
46 | |||
47 | import java.io.*; | ||
48 | import java.util.*; | ||
49 | |||
50 | import de.jarnbjo.ogg.*; | ||
51 | |||
52 | /** | ||
53 | * Replacement file reader class. The original J-Ogg FileStream has the | ||
54 | * major disadvantage that it reads the entire file, even though we just | ||
55 | * need a few byte from it. This FastFileStream will only read as little | ||
56 | * information as possible. | ||
57 | * | ||
58 | * @author Richard Körber <dev@shredzone.de> | ||
59 | * @version $Id$ | ||
60 | */ | ||
61 | public class OggFastFileStream implements PhysicalOggStream { | ||
62 | private InputStream sourceStream; | ||
63 | private boolean closed = false; | ||
64 | private int contentLength = 0; | ||
65 | private int position = 0; | ||
66 | private HashMap logicalStreams = new HashMap(); | ||
67 | private OggPage firstPage; | ||
68 | |||
69 | /** | ||
70 | * Constructor for the OggFastFileStream object | ||
71 | * | ||
72 | * @param in RandomAccessFile to be read | ||
73 | * @throws OggFormatException Bad format | ||
74 | * @throws IOException IO error | ||
75 | */ | ||
76 | public OggFastFileStream( RandomAccessFile in ) | ||
77 | throws OggFormatException, IOException { | ||
78 | this.sourceStream = new RandomAdapterInputStream( in ); | ||
79 | contentLength = (int) in.length(); | ||
80 | firstPage = OggPage.create( sourceStream ); | ||
81 | position += firstPage.getTotalLength(); | ||
82 | LogicalOggStreamImpl los = new LogicalOggStreamImpl( this, firstPage.getStreamSerialNumber() ); | ||
83 | logicalStreams.put( new Integer( firstPage.getStreamSerialNumber() ), los ); | ||
84 | los.checkFormat( firstPage ); | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * Get a collection of the logical streams. | ||
89 | * | ||
90 | * @return Collection | ||
91 | */ | ||
92 | public Collection getLogicalStreams() { | ||
93 | return logicalStreams.values(); | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * Checks if the file is open. | ||
98 | * | ||
99 | * @return true: open, false: closed | ||
100 | */ | ||
101 | public boolean isOpen() { | ||
102 | return !closed; | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * Closes the stream | ||
107 | * | ||
108 | * @throws IOException IO error | ||
109 | */ | ||
110 | public void close() | ||
111 | throws IOException { | ||
112 | closed = true; | ||
113 | sourceStream.close(); | ||
114 | } | ||
115 | |||
116 | /** | ||
117 | * Get the content length | ||
118 | * | ||
119 | * @return The content length | ||
120 | */ | ||
121 | public int getContentLength() { | ||
122 | return contentLength; | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * Get the current position | ||
127 | * | ||
128 | * @return Position | ||
129 | */ | ||
130 | public int getPosition() { | ||
131 | return position; | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * Get an OggPage. | ||
136 | * | ||
137 | * @param index Index to be fetched | ||
138 | * @return The oggPage value | ||
139 | * @throws IOException IO Error | ||
140 | */ | ||
141 | public OggPage getOggPage( int index ) | ||
142 | throws IOException { | ||
143 | if( firstPage != null ) { | ||
144 | OggPage tmp = firstPage; | ||
145 | firstPage = null; | ||
146 | return tmp; | ||
147 | } else { | ||
148 | OggPage page = OggPage.create( sourceStream ); | ||
149 | position += page.getTotalLength(); | ||
150 | return page; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * Move the stream to a certain time position. | ||
156 | * | ||
157 | * @param granulePosition The new position | ||
158 | * @throws IOException | ||
159 | */ | ||
160 | public void setTime( long granulePosition ) | ||
161 | throws IOException { | ||
162 | throw new UnsupportedOperationException( "not supported" ); | ||
163 | } | ||
164 | |||
165 | /** | ||
166 | * Is this FileStream seekable? We pretend we are not, so J-Ogg | ||
167 | * will not get some stupid thoughts... ;) | ||
168 | * | ||
169 | * @return false | ||
170 | */ | ||
171 | public boolean isSeekable() { | ||
172 | return false; | ||
173 | } | ||
174 | |||
175 | /*--------------------------------------------------------------------*/ | ||
176 | |||
177 | /** | ||
178 | * This class repairs a design flaw in JDK1.0. A RandomAccessFile | ||
179 | * is not derived from InputStream, though it provides the same API. | ||
180 | * This Adapter gives an InputStream view of a Random Access File. | ||
181 | * <p> | ||
182 | * For a detailed method description, see InputStream. | ||
183 | */ | ||
184 | private static class RandomAdapterInputStream extends InputStream { | ||
185 | private RandomAccessFile rf; | ||
186 | |||
187 | /** | ||
188 | * Create a new Adapter. | ||
189 | * | ||
190 | * @param rf RandomAccessFile to be used | ||
191 | */ | ||
192 | public RandomAdapterInputStream( RandomAccessFile rf ) { | ||
193 | this.rf = rf; | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * Read a byte. | ||
198 | * | ||
199 | * @return Read byte or -1. | ||
200 | */ | ||
201 | public int read() throws IOException { | ||
202 | return rf.read(); | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * Read a byte array. | ||
207 | * | ||
208 | * @param b Byte array to be read | ||
209 | * @return Number of bytes read or -1 | ||
210 | */ | ||
211 | public int read( byte[] b) throws IOException { | ||
212 | return rf.read(b); | ||
213 | } | ||
214 | |||
215 | /** | ||
216 | * Read into a byte array. | ||
217 | * | ||
218 | * @param b Byte array to be read | ||
219 | * @param off Starting offset | ||
220 | * @param len Length | ||
221 | * @return Number of bytes read or -1 | ||
222 | */ | ||
223 | public int read( byte[] b, int off, int len) throws IOException { | ||
224 | return rf.read( b, off, len ); | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * Skip a number of bytes in forward direction. | ||
229 | * | ||
230 | * @param n Number of bytes to skip | ||
231 | * @return Number of bytes skipped, or -1 | ||
232 | */ | ||
233 | public long skip( long n ) throws IOException { | ||
234 | return rf.skipBytes( (int) n ); | ||
235 | } | ||
236 | |||
237 | /** | ||
238 | * Return the number of available bytes. Here it is the number of | ||
239 | * bytes remaining until EOF. | ||
240 | * | ||
241 | * @return Number of bytes available. | ||
242 | */ | ||
243 | public int available() throws IOException { | ||
244 | return (int) (rf.length() - rf.getFilePointer()); | ||
245 | } | ||
246 | |||
247 | } | ||
248 | |||
249 | } | ||