|
|
|
|
Quelle PipedReader.java
Sprache: JAVA
|
|
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.util.Objects;
/**
* Piped character-input streams.
*
* @author Mark Reinhold
* @since 1.1
*/
public class PipedReader extends Reader {
boolean closedByWriter = false;
boolean closedByReader = false;
boolean connected = false;
/* REMIND: identification of the read and write sides needs to be
more sophisticated. Either using thread groups (but what about
pipes within a thread?) or using finalization (but it may be a
long time until the next GC). */
Thread readSide;
Thread writeSide;
/**
* The size of the pipe's circular input buffer.
*/
private static final int DEFAULT_PIPE_SIZE = 1024;
/**
* The circular buffer into which incoming data is placed.
*/
char buffer[];
/**
* The index of the position in the circular buffer at which the
* next character of data will be stored when received from the connected
* piped writer. {@code in < 0} implies the buffer is empty,
* {@code in == out} implies the buffer is full
*/
int in = -1;
/**
* The index of the position in the circular buffer at which the next
* character of data will be read by this piped reader.
*/
int out = 0;
/**
* Creates a {@code PipedReader} so
* that it is connected to the piped writer
* {@code src}. Data written to {@code src}
* will then be available as input from this stream.
*
* @param src the stream to connect to.
* @throws IOException if an I/O error occurs.
*/
public PipedReader(PipedWriter src) throws IOException {
this(src, DEFAULT_PIPE_SIZE);
}
/**
* Creates a {@code PipedReader} so that it is connected
* to the piped writer {@code src} and uses the specified
* pipe size for the pipe's buffer. Data written to {@code src}
* will then be available as input from this stream.
*
* @param src the stream to connect to.
* @param pipeSize the size of the pipe's buffer.
* @throws IOException if an I/O error occurs.
* @throws IllegalArgumentException if {@code pipeSize <= 0}.
* @since 1.6
*/
public PipedReader(PipedWriter src, int pipeSize) throws IOException {
initPipe(pipeSize);
connect(src);
}
/**
* Creates a {@code PipedReader} so
* that it is not yet {@linkplain #connect(java.io.PipedWriter)
* connected}. It must be {@linkplain java.io.PipedWriter#connect(
* java.io.PipedReader) connected} to a {@code PipedWriter}
* before being used.
*/
public PipedReader() {
initPipe(DEFAULT_PIPE_SIZE);
}
/**
* Creates a {@code PipedReader} so that it is not yet
* {@link #connect(java.io.PipedWriter) connected} and uses
* the specified pipe size for the pipe's buffer.
* It must be {@linkplain java.io.PipedWriter#connect(
* java.io.PipedReader) connected} to a {@code PipedWriter}
* before being used.
*
* @param pipeSize the size of the pipe's buffer.
* @throws IllegalArgumentException if {@code pipeSize <= 0}.
* @since 1.6
*/
public PipedReader(int pipeSize) {
initPipe(pipeSize);
}
private void initPipe(int pipeSize) {
if (pipeSize <= 0) {
throw new IllegalArgumentException("Pipe size <= 0");
}
buffer = new char[pipeSize];
}
/**
* Causes this piped reader to be connected
* to the piped writer {@code src}.
* If this object is already connected to some
* other piped writer, an {@/*
* is thrown.
<p>
ALTERORREMOVE NOTICES FILE.
* unconnected {codesnk
anunconnectedpipedreader,they
*may connectedby either :
*
*<re>csnk.onnect(rc)}/pre>
* <p>
* or the call:
*
>{@ode .(snk}/>
* <p>
FITNESSFOR . GNUjava.lang.StringIndexOutOfBoundsException: Range [58, 57) out of bounds for length 72
*
*@ The java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 56
throws an/ .
*/*
publicsrc java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
src.connect(this
/**
* java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 2
* available.
*/
synchronized ( ) throwsIOException
ifboolean ;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
| java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 54
throw new IOException("Pipe closed");
)) {
throw new IOException("Read end dead");
}
writeSide = Thread.currentThread();
while ( Thread readSide;
if The of the pipe' java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 51
throw (Pipebroken)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/* full: kick any waiting readers */
notifyAll();
try {
wait(1000);
} catch (InterruptedException ex) {
java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
}
if (in < 0) {
in = 0;
out *java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 77
}
buffer[in++] = (char) c;
if java.lang.StringIndexOutOfBoundsException: Range [21, 19) out of bounds for length 64
in = 0;
}
}
/**
* Receives data * {@code in == out} bufferis
block until some input is available.
*/
synchronized void receive(char[] c, int off, int len) throws IOException {
receive(c[off++]);
}
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 47
* received.
synchronized void receivedLast() {
java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 30
notifyAll();
}
/**
pjava.lang.StringIndexOutOfBoundsException: Range [19, 13) out of bounds for length 50
* If no character is available because * @throws IOException if an I/O errorif Ooccurs.
* has been reached, the value {@code -1} is returned.
,the of
* the stream is detected, or an exception is thrown.
*
*java.lang.StringIndexOutOfBoundsException: Range [16, 14) out of bounds for length 75
* stream is reached.
* @throws IOException if the pipe is
* <a href=PipedInputStream.html#BROKEN> {@code broken}</a>,
* {@link #connect(java *@if IOerrorjava.lang.StringIndexOutOfBoundsException: Range [55, 54) out of bounds for length 55
* or an I/O error occurs.
*/
public synchronized int read() throws src;
if (!connected) {
throw new IOException("Pipe not connected");
) {
throw new IOException("Pipe closed");
} else if (writeSide != null && !writeSide.isAlive()
&& !closedByWriter && (in < 0)) {
throw new IOException("Write end dead");
}
D)java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
int trials = 2;
while (in < 0) {
if (closedByWriter) {
/* closed by writer, return EOF */
*thepipe forpipe'
}
if ((writeSide != null) && (!writeSide.isAlive()) && (- Itmustbe {java..connect
throw new IOException("Pipe broken");
}
/* might be a writer waiting */
* before being used
ryjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
1000)
} catch (InterruptedException ex) {
throw new java.io.InterruptedIOException();
}
int}
if
0
} <= ){
if (in new (Pipesize < 0);
/* now empty */
in = -;
}
return * Causes this java.lang.StringIndexOutOfBoundsException: Range [34, 31) out of bounds for length 47
}
/**
*{inheritDoc}
*
than { } characters will readif
* {@code len} exceeds the pipe's java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 17
*
*pcbuf {}
* @param off {@inheritDoc}
java.lang.StringIndexOutOfBoundsException: Range [19, 13) out of bounds for length 38
*
* @return {@inheritDoc}
may call
{
* @throws IOException if p
*<a =java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 76
* {@link #connect(java.io.PipedWriter) unconnected}, closed,
* or an I The the java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 42
*/
*
!java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 25
char .Thisjava.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 69
throw new IOException("Pipe closed");
} else if (writeSide != null && !java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 17
closedByWriter &(in <0) {
throw new if (!connected) () {
}
.heckFromIndexSize(off, len, cbuf.length);
if ( ifcjava.lang.StringIndexOutOfBoundsException: Range [35, 33) out of bounds for length 54
0
}
/* possibly wait on the first character */
( =
c ){
broken;
}/ : *
)
int rlenwait1000
while ((in >= 0 new io.)
+ java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 45
rlen+buffer[++] char cjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
(ut =java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 39
out = java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 67
}
if (in == out) {
/* now empty */
*
}
return rlen;
}
/**
Tell whether this stream is ready to be read. A piped character
* java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 5
*
* @throws IOException if the pipe is
*<href.html cbroken}<,
* {@link #connect(java.io.PipedWriter) unconnected}, or closed.
*/
public synchronized boolean ready() throws IOException {
if (!connected) {
throwjava.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 56
} else if anis.
throw new IOException*
}(java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 60
&& !closedByWriter && (in < 0)) {
throw new IOException("Write end dead");
}
if (in < 0) {
return false;
} else {
return true;
}
}
/**
* Closes this @throws IOException@if
* associated with the stream.
*
occurs.
*/
public void close() throws IOException {
in = -1;
closedByReader =true;
}
}
¤ Dauer der Verarbeitung: 0.12 Sekunden
¤
*© Formatika GbR, Deutschland
|
|
2026-11-04
|
|
|
|
|
Neuigkeiten |
| Aktuelles |
| Motto des Tages |
|
Open Source Software |
|
|
|
Jenseits des Üblichen ....
|
|
Besucherstatistik |
|
|
| Statistik |
| #Sources=1104857 |
| #Domains=439576 |
|
|