1 package nom.tam.util;
2
3 /*
4 * #%L
5 * nom.tam FITS library
6 * %%
7 * Copyright (C) 1996 - 2024 nom-tam-fits
8 * %%
9 * This is free and unencumbered software released into the public domain.
10 *
11 * Anyone is free to copy, modify, publish, use, compile, sell, or
12 * distribute this software, either in source code form or as a compiled
13 * binary, for any purpose, commercial or non-commercial, and by any
14 * means.
15 *
16 * In jurisdictions that recognize copyright laws, the author or authors
17 * of this software dedicate any and all copyright interest in the
18 * software to the public domain. We make this dedication for the benefit
19 * of the public at large and to the detriment of our heirs and
20 * successors. We intend this dedication to be an overt act of
21 * relinquishment in perpetuity of all present and future rights to this
22 * software under copyright law.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
28 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30 * OTHER DEALINGS IN THE SOFTWARE.
31 * #L%
32 */
33
34 import java.io.IOException;
35
36 /**
37 * Interface for basic random access read and write operations. Because it is
38 * built on the elements used by {@link FitsEncoder} and {@link FitsDecoder}, in
39 * principle it can serve as the common point for reading and writing FITS
40 * binary data in memory (using {@link ByteArrayIO}) or in a file (using
41 * {@link FitsFile} or a subclass thereof). For that reason, addressing is
42 * assumed as 64-bit <code>long</code> type.
43 *
44 * @author Attila Kovacs
45 * @since 1.16
46 */
47 public interface ReadWriteAccess extends InputReader, OutputWriter {
48
49 /**
50 * Returns the current read/write position in this instance. The position
51 * may exceed the length, depending on implementation, just as
52 * <code>seek</code> may go beyond the file size in
53 * {@link java.io.RandomAccessFile}.
54 *
55 * @return the current read/write position.
56 * @throws IOException
57 * if there was an IO error.
58 * @see #position(long)
59 * @see #length()
60 */
61 long position() throws IOException;
62
63 /**
64 * Sets a new position for the next read or write in this instance. The
65 * position may exceed the length, depending on implementation, just as
66 * <code>seek</code> may go beyond the file size in
67 * {@link java.io.RandomAccessFile}.
68 *
69 * @param n
70 * the new read/write position.
71 * @throws IOException
72 * if there was an IO error.
73 * @see #position()
74 * @see #length()
75 */
76 void position(long n) throws IOException;
77
78 /**
79 * Returns the current total length of this instance, that is the total
80 * number of bytes that may be read from it.
81 *
82 * @return the total number of bytes contained in this instance
83 * @throws IOException
84 * if there was an IO error.
85 */
86 long length() throws IOException;
87
88 }