View Javadoc
1   /*
2    * dpkg - Debian Package library and the Debian Package Maven plugin
3    * (c) Copyright 2015 Gerrit Hohl
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18   */
19  package net.sourceforge.javadpkg.io;
20  
21  import java.io.Closeable;
22  import java.io.IOException;
23  import java.io.InputStream;
24  
25  /**
26   * <p>
27   * The source for reading data.
28   * </p>
29   *
30   * @author Gerrit Hohl (gerrit-hohl@users.sourceforge.net)
31   * @version <b>1.0</b>, 31.12.2015 by Gerrit Hohl
32   */
33  public interface DataSource extends Closeable {
34  
35  
36  	/**
37  	 * <p>
38  	 * Returns the name of the source.
39  	 * </p>
40  	 * <p>
41  	 * This name is used e.g. for detail messages of exceptions.
42  	 * </p>
43  	 *
44  	 * @return The name.
45  	 */
46  	String getName();
47  
48  
49  	/**
50  	 * <p>
51  	 * Returns the length of the data which can be read from the source in
52  	 * bytes.
53  	 * </p>
54  	 *
55  	 * @return The length or <code>-1</code>, if the length is unknown.
56  	 */
57  	long getLength();
58  
59  
60  	/**
61  	 * <p>
62  	 * Returns the flag if the source can be reseted.
63  	 * </p>
64  	 *
65  	 * @return The flag: <code>true</code>, if the source can be reseted,
66  	 *         <code>false</code> otherwise.
67  	 * @see #reset()
68  	 */
69  	boolean isResettable();
70  
71  
72  	/**
73  	 * <p>
74  	 * Resets the source.
75  	 * </p>
76  	 * <p>
77  	 * If the source can't be reseted an {@link IOException} will be thrown.
78  	 * </p>
79  	 * <p>
80  	 * If the source can be reseted the next call of the
81  	 * {@link #getInputStream()} method will return a new {@link InputStream}
82  	 * which reads the source from the beginning again.
83  	 * </p>
84  	 * 
85  	 * @throws IOException
86  	 *             If an I/O error occurs or if the source doesn't support a
87  	 *             reset.
88  	 * @see #isResettable()
89  	 */
90  	void reset() throws IOException;
91  
92  
93  	/**
94  	 * <p>
95  	 * Returns a stream for reading the data.
96  	 * </p>
97  	 * <p>
98  	 * The method will always return the same {@link InputStream} if the source
99  	 * is still open. If the {@link InputStream#close()} method is called the
100 	 * source will behave the same as the {@link #close()} method was called.
101 	 * </p>
102 	 * <p>
103 	 * If the {@link #reset()} method was successfully called the method will
104 	 * return a different {@link InputStream}.
105 	 * </p>
106 	 *
107 	 * @return The stream.
108 	 * @throws IOException
109 	 *             If an I/O error occurs.
110 	 */
111 	InputStream getInputStream() throws IOException;
112 
113 
114 }