Input streaming for judging character ending

zhaozj2021-02-16  85

Import java.io.ioException; import java.io.Inputstream;

Public class charterminatedInputStream extends inputstream {

PRIVATE INPUTSTREAM IN;

Private int match [];

Private int buffer [];

Private int POS = 0;

PRIVATE BOOLEAN EndFound = FALSE

public CharTerminatedInputStream (InputStream in, byte [] terminator) {if (terminator == null) {throw new IllegalArgumentException ( "The terminating character array can not be null.");} if (terminator.length == 0) {throw new IllegalArgumentException ("The Terminating Character Array Cannot BE of Zero Length);} match = new int [Terminator.Length]; buffer = new int [Terminator.Length]; for (int i = 0; i

Public synchronized void reset () {endfound = false; pOS = 0;}

Public int ready () throws oException {

IF (endfound) {return -1;}

IF (POS == 0) {INT B = IN.READ (); if (b == -1) {endfound = true; return -1;} if (b! = match [0]) {RETURN B;} Buffer [0] = B; POS ;} else {if (buffer [0]! = match [0]) {Return Topchar ();}}} for (int i = 0; i = POS) {INT B = in.read (); if (b == -1) {Return Topchar ();} buffer [POS] = B; POS ;} if (buffer [i]! = match [i]) {return Topchar ();}} endfound = true; Return -1;}

转载请注明原文地址:https://www.9cbs.com/read-13806.html

New Post(0)