1 /*
2 * Copyright (c) 2003 Peter Antman, Teknik i Media <peter.antman@tim.se>
3 *
4 * $Id: FileCachedInputStream.java,v 1.1.1.1 2004/05/19 12:07:30 pra Exp $
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 package org.backsource.utils.io;
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 /***
25 * Cached input stream that reads from a possibly temp file.
26 *
27 * @author <a href="mailto:pra@tim.se">Peter Antman</a>
28 * @version $Revision: 1.1.1.1 $
29 */
30
31 public class FileCachedInputStream extends CachedInputStream{
32 File file;
33 /***
34 * Get a CachedInputStream from the CachedOutputStream.
35 */
36 public FileCachedInputStream (FileCachedOutputStream cout) throws IOException{
37 this( (File)cout.getSink() );
38 }
39 public FileCachedInputStream (File file) throws IOException{
40 super(new FileInputStream(file));
41 this.file = file;
42 }
43
44 /***
45 * Resets all buffers and opens a new FileInputStream.
46 */
47 public void rewind() throws IOException {
48 try {
49 in.close();
50 } catch (Exception ignore) {
51 ;//Ingnore
52 } // end of try-catch
53 buf = new byte[buf.length];
54 count = 0;
55 pos = 0;
56 markpos = -1;
57 in = new FileInputStream(file);
58 }
59
60
61 }// FileCachedInputStream