1
/***** BEGIN LICENSE BLOCK *****
2
* Version: CPL 1.0/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Common Public
5
* License Version 1.0 (the "License"); you may not use this file
6
* except in compliance with the License. You may obtain a copy of
7
* the License at http://www.eclipse.org/legal/cpl-v10.html
9
* Software distributed under the License is distributed on an "AS
10
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11
* implied. See the License for the specific language governing
12
* rights and limitations under the License.
14
* Copyright (C) 2008 The JRuby Community <www.jruby.org>
16
* Alternatively, the contents of this file may be used under the terms of
17
* either of the GNU General Public License Version 2 or later (the "GPL"),
18
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19
* in which case the provisions of the GPL or the LGPL are applicable instead
20
* of those above. If you wish to allow use of your version of this file only
21
* under the terms of either the GPL or the LGPL, and not to allow others to
22
* use your version of this file under the terms of the CPL, indicate your
23
* decision by deleting the provisions above and replace them with the notice
24
* and other provisions required by the GPL or the LGPL. If you do not delete
25
* the provisions above, a recipient may use your version of this file under
26
* the terms of any one of the CPL, the GPL or the LGPL.
27
***** END LICENSE BLOCK *****/
28
package org.jruby.util.io;
30
import java.io.EOFException;
31
import java.io.IOException;
32
import java.io.InputStream;
33
import java.io.OutputStream;
34
import org.jruby.util.ByteList;
35
import org.jruby.Ruby;
39
public interface Stream {
40
public static final int SEEK_SET = 0;
41
public static final int SEEK_CUR = 1;
42
public static final int SEEK_END = 2;
44
// We use a highly uncommon string to represent the paragraph delimiter (100% soln not worth it)
45
public static final ByteList PARAGRAPH_DELIMETER = ByteList.create("PARAGRPH_DELIM_MRK_ER");
47
public static final ByteList PARAGRAPH_SEPARATOR = ByteList.create("\n\n");
49
public ChannelDescriptor getDescriptor();
51
public void clearerr();
53
public ModeFlags getModes();
55
public boolean isSync();
57
public void setSync(boolean sync);
59
public abstract ByteList fgets(ByteList separatorString) throws IOException, BadDescriptorException, EOFException;
60
public abstract ByteList readall() throws IOException, BadDescriptorException, EOFException;
61
public abstract int getline(ByteList dst, byte terminator) throws IOException, BadDescriptorException;
62
// TODO: We overflow on large files...We could increase to long to limit
63
// this, but then the impl gets more involved since java io APIs based on
64
// int (means we have to chunk up a long into a series of int ops).
66
public abstract ByteList fread(int number) throws IOException, BadDescriptorException, EOFException;
67
public abstract int fwrite(ByteList string) throws IOException, BadDescriptorException;
69
public abstract int fgetc() throws IOException, BadDescriptorException, EOFException;
70
public abstract int ungetc(int c);
71
public abstract void fputc(int c) throws IOException, BadDescriptorException;
73
public abstract ByteList read(int number) throws IOException, BadDescriptorException, EOFException;
75
public abstract void fclose() throws IOException, BadDescriptorException;
76
public abstract int fflush() throws IOException, BadDescriptorException;
79
* <p>Flush and sync all writes to the filesystem.</p>
81
* @throws IOException if the sync does not work
83
public void sync() throws IOException, BadDescriptorException;
86
* <p>Return true when at end of file (EOF).</p>
88
* @return true if at EOF; false otherwise
90
* @throws BadDescriptorException
92
public boolean feof() throws IOException, BadDescriptorException;
95
* <p>Get the current position within the file associated with this
98
* @return the current position in the file.
100
* @throws PipeException ESPIPE (illegal seek) when not a file
103
public long fgetpos() throws IOException, PipeException, BadDescriptorException, InvalidValueException;
106
* <p>Perform a seek based on pos(). </p>
107
* @throws IOException
108
* @throws PipeException
109
* @throws InvalidValueException
111
public void lseek(long offset, int type) throws IOException, InvalidValueException, PipeException, BadDescriptorException;
112
public void ftruncate(long newLength) throws IOException, PipeException,
113
InvalidValueException, BadDescriptorException;
116
* Implement IO#ready? as per io/wait in MRI.
117
* returns non-nil if input available without blocking, or nil.
119
public int ready() throws IOException;
122
* Implement IO#wait as per io/wait in MRI.
123
* waits until input available or timed out and returns self, or nil when EOF reached.
125
* The default implementation loops while ready returns 0.
127
public void waitUntilReady() throws IOException, InterruptedException;
129
public boolean readDataBuffered();
130
public boolean writeDataBuffered();
132
public InputStream newInputStream();
134
public OutputStream newOutputStream();
136
public boolean isBlocking();
138
public void setBlocking(boolean blocking) throws IOException;
140
public void freopen(Ruby runtime, String path, ModeFlags modes) throws DirectoryAsFileException, IOException, InvalidValueException, PipeException, BadDescriptorException;