~ubuntu-branches/ubuntu/lucid/jruby/lucid

« back to all changes in this revision

Viewing changes to src/org/jruby/util/io/Stream.java

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Delafond
  • Date: 2009-12-09 17:30:55 UTC
  • Revision ID: james.westby@ubuntu.com-20091209173055-8ffzikq1768gywux
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***** BEGIN LICENSE BLOCK *****
 
2
 * Version: CPL 1.0/GPL 2.0/LGPL 2.1
 
3
 *
 
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
 
8
 *
 
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.
 
13
 *
 
14
 * Copyright (C) 2008 The JRuby Community <www.jruby.org>
 
15
 * 
 
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;
 
29
 
 
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;
 
36
 
 
37
/**
 
38
 */
 
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;
 
43
    
 
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");
 
46
    
 
47
    public static final ByteList PARAGRAPH_SEPARATOR = ByteList.create("\n\n");
 
48
    
 
49
    public ChannelDescriptor getDescriptor();
 
50
    
 
51
    public void clearerr();
 
52
    
 
53
    public ModeFlags getModes();
 
54
    
 
55
    public boolean isSync();
 
56
 
 
57
    public void setSync(boolean sync);
 
58
 
 
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).
 
65
 
 
66
    public abstract ByteList fread(int number) throws IOException, BadDescriptorException, EOFException;
 
67
    public abstract int fwrite(ByteList string) throws IOException, BadDescriptorException;
 
68
 
 
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;
 
72
    
 
73
    public abstract ByteList read(int number) throws IOException, BadDescriptorException, EOFException;
 
74
    
 
75
    public abstract void fclose() throws IOException, BadDescriptorException;
 
76
    public abstract int fflush() throws IOException, BadDescriptorException;
 
77
    
 
78
    /**
 
79
     * <p>Flush and sync all writes to the filesystem.</p>
 
80
     * 
 
81
     * @throws IOException if the sync does not work
 
82
     */
 
83
    public void sync() throws IOException, BadDescriptorException;
 
84
    
 
85
    /**
 
86
     * <p>Return true when at end of file (EOF).</p>
 
87
     * 
 
88
     * @return true if at EOF; false otherwise
 
89
     * @throws IOException 
 
90
     * @throws BadDescriptorException 
 
91
     */
 
92
    public boolean feof() throws IOException, BadDescriptorException;
 
93
    
 
94
    /**
 
95
     * <p>Get the current position within the file associated with this
 
96
     * handler.</p>  
 
97
     * 
 
98
     * @return the current position in the file.
 
99
     * @throws IOException 
 
100
     * @throws PipeException ESPIPE (illegal seek) when not a file 
 
101
     * 
 
102
     */
 
103
    public long fgetpos() throws IOException, PipeException, BadDescriptorException, InvalidValueException;
 
104
    
 
105
    /**
 
106
     * <p>Perform a seek based on pos().  </p> 
 
107
     * @throws IOException 
 
108
     * @throws PipeException 
 
109
     * @throws InvalidValueException 
 
110
     */
 
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;
 
114
    
 
115
    /**
 
116
     * Implement IO#ready? as per io/wait in MRI.
 
117
     * returns non-nil if input available without blocking, or nil.
 
118
     */
 
119
    public int ready() throws IOException;
 
120
 
 
121
    /**
 
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.
 
124
     *
 
125
     * The default implementation loops while ready returns 0.
 
126
     */
 
127
    public void waitUntilReady() throws IOException, InterruptedException;
 
128
 
 
129
    public boolean readDataBuffered();
 
130
    public boolean writeDataBuffered();
 
131
    
 
132
    public InputStream newInputStream();
 
133
    
 
134
    public OutputStream newOutputStream();
 
135
    
 
136
    public boolean isBlocking();
 
137
    
 
138
    public void setBlocking(boolean blocking) throws IOException;
 
139
    
 
140
    public void freopen(Ruby runtime, String path, ModeFlags modes) throws DirectoryAsFileException, IOException, InvalidValueException, PipeException, BadDescriptorException;
 
141
}