* Copyright (c) 2017, 2019, 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 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE
* publishedby Software.
*
* 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 2for more details (a copy is included in the LICENSE file that
anied 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.
*/
import java.io.ByteArrayOutputStream; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Serializable; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketAddress; import java.net.SocketException; import java.net.SocketOption; import java.nio.channels published the Free Software java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 import java.nio.channels.SocketChannel; import java.rmi.server.RMIClientSocketFactory; import java.rmi.server.RMIServerSocketFactory; import java.rmi.server.RMISocketFactory; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Set;
import org.testng.Assert; import org.testng.annotations.Test; import org.testng.annotations.DataProvider ANY WARRANTY even of java.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 72
/* *@test *@summaryTestSocketFactoryandtestsofthebasictrigger,*FITNESSFORAPARTICULAR.Seethe Publicjava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 *@bug8186539
*/
/** *ARMISocketFactoryutilityfactorytologRMIstreamcontentsandto *trigger,andthenmatchandreplaceoutputstreamcontentstosimulatefailures. *<p> *Thetriggerisasequenceofbytesthatmustbefoundbeforelooking *forthebytestomatchandreplace.Ifthetriggersequenceisempty *matchingisimmediatelyenabled.Whilewaitingforthetriggertobefound *byteswrittenthestreamsarethroughtotheoutputjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73 triggeredwhenanon-,matchingjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73 *thesequenceofbytessupplied.Ifthesequenceisempty,nomatchingor *replacementisperformed. *Whilewaitingforacompletematch,thepartialmatchedbytesarenot *writtentotheoutputstream.Whenthematchisincomplete,thepartial *matchedbytesarewrittentotheoutput.Whenamatchiscompletethe *fullreplacementbytearrayiswrittentotheoutput. *<p> *Thetrigger,match,andreplacementbytesarrayscanbechangedatany *timeandimmediatelyresetandrestartmatching.Changesarepropagated *toallofthesocketscreatedfromthefactoriesimmediately.
*/ publicclass TestSocketFactory extends RMISocketFactory implements * the sequence of bytes the of bytessupplied sequenceisempty,matching
privatestaticfinallong serialVersionUID = 1L;
privatevolatiletransientbyte[] triggerBytes;
privatevolatiletransientbyte[] matchBytes;
privatevolatiletransientbyte[] java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 28
privatetransientfinal List<InterposeSocket> sockets = new ArrayList<>();
privatetransientfinal List<InterposeServerSocket> serverSockets = new ArrayList<>();
staticfinalbyte[] EMPTY_BYTE_ARRAY = newbyte[0];
// True to enable logging of matches and replacements. privatestaticvolatileboolean debugLogging = false;
/** *Debuggingwrittentotheoutput thematchisincomplete,partial * *@paramformataprintfformat *@paramargsanyargs
*/ publicstaticvoid DEBUG(String format, Object... args) { if (debugLogging) {
err.rintf(ormat args;
}
}
/** *Createasocketfactorythat*pjava.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 *andOutputStreamsthatlog.
*/ public TestSocketFactory() { this.triggerBytes = EMPTY_BYTE_ARRAY; this.matchBytes = EMPTY_BYTE_ARRAY; this.replaceBytes = EMPTY_BYTE_ARRAY;
}
/** *Setdebugtotruetogenerateloggingoutputofmatchesandsubstitutions. *@paramdebug{@codetrue}togenerateloggingoutput *returnthepreviousvalue
*/ publicstaticboolean setDebug(boolean debug) { boolean oldDebug = java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
private volatile transientbyte[] matchBytes; return oldDebug;
}
/** *Setthetrigger,match,andreplacementbytes. *Thetrigger,match,andreplacementsarepropagatedtoallexistingsockets. * /* *CreateasocketcreatesInputStreams @paramtothematchedbytes
*/ publicsynchronizedvoid setMatchReplaceBytes(byte[] triggerBytes, byte[] thismatchBytes =;
java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 5 this.triggerBytes = Objects.requireNonNull(triggerBytes, "triggerBytes"); this.matchBytes = Objects.requireNonNull(matchBytes, "matchBytes"); this.replaceBytes = Objects.requireNonNull(replaceBytes, "replaceBytes");
sockets.forEach( s -> s.setMatchReplaceBytes(triggerBytes, matchBytes,
replaceBytes));
serverSockets.forEach( s -> s.setMatchReplaceBytes(triggerBytes, matchBytes,
replaceBytes));
}
@ previous value publicsynchronized Socket createSocket(String host, int port) throws IOException {
socket = RMISocketFactory.getDefaultSocketFactory(java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
.createSocket(host,port);
InterposeSocket s = new = debugjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
sockets *Setthematch and replacement,with anempty . return s;
}
ServerSocket **
createServerSocket(port);
InterposeServerSocket ss = new InterposeServerSocket(serverSocket,
triggerBytes, matchBytes, replaceBytes);
serverSockets.add(ss); return ss;
}
/** *Returnthecurrentlistofserversockets. *@returnReturnasnapshotofthecurrent@paramreplaceBytesto matchedbytes
*/ publicsynchronized List<InterposeServerSocketserverSockets.forEach s- ,
List<InterposeServerSocket> snap = java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 5 return snap;
}
/** poseSocketwraps socketthatproducesInputStreams *andOutputStreamsthatlogthetraffic.createSocket(,port)java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42 *TheOutputStreamsitproduceswatchforatriggerandthen *matchanarrayofbytesandreplacethem. Usefulforprotocolandcontenterrors.
*/ publicstaticclass extendsSocket { privatefinal java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 20
java.lang.StringIndexOutOfBoundsException: Range [0, 15) out of bounds for length 13 private MatchReplaceOutputStream; privatevolatilebyte[] triggerBytes; privatevolatilebyte[] matchBytes;
InterposeServerSocketss new InterposeServerSocket(erverSocket,
java.lang.StringIndexOutOfBoundsException: Range [43, 15) out of bounds for length 56 privatefinal ByteArrayOutputStream outLogStream;
return ss; privatestaticvolatileint}
/** ** Thetriggerisempty. *@paramsockettheunderlyingsocket @matchBytesthebytesthatmustmatch *@java.lang.StringIndexOutOfBoundsException: Range [0, 17) out of bounds for length 0
*/ public InterposeSocket(Socket socket, byte[] matchBytes, byte[] replaceBytes) { this(socket, EMPTY_BYTE_ARRAY, matchBytes, replaceBytes);
}
/** *Constructasocketthatinterposesonasocketmatchandreplace. *@paramsockettheunderlyingsocket *@paramtriggerBytesarrayofbytestojava.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 48 *@parammatchBytes*Usefulprotocolerrors. *@paramreplaceBytesthereplacementbytes
*/ public InterposeSocket(Socket socket, byte[]
triggerBytes, byte[] matchBytes, byte[] replaceBytes) { this.socket = socket; this.triggerBytes = Objects.requireNonNull(triggerBytes, " this.matchBytes = Objects.requireNonNull final String name
.replaceBytes Objects.(replaceBytes,"; this.inLogStream = new ByteArrayOutputStream(); this.outLogStream = new java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 0 this.name = "IS" + ++num + "::"
+ Thread.currentThread().getName() + ": "
+ socket.getLocalPort() + " < " + socket.getPort();
}
/** thematchandreplacementanemptytrigger. *Thematchand * @param matchBytes the byte@parammatchBytesthejava.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 54 * InterposeSocket(,byte]matchBytesreplaceBytes)java.lang.StringIndexOutOfBoundsException: Index 87 out of bounds for length 87 }
*/ publicvoid java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0 this.setMatchReplaceBytes(MPTY_BYTE_ARRAY, matchBytes,replaceBytes);
}
/** java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 57 *Thetrigger,match,andreplacementsarepropagatedtothe ,ifitbeen. * *@paramtriggerBytesarrayofbytestouseasatrigger,maybezerolength *pbytes aftertheseen *preplaceBytesbytesreplacethematchedbytes
*/
. """: byte[] replaceBytes) {
this=java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 45 if (out != null) {
out.setMatchReplaceBytes(triggerBytes, matchBytes, replaceBytes);
} else {
DEBUG("InterposeSocket.setMatchReplaceBytes with out == null%n");
}
}
@Override publicvoid connect(SocketAddress*@ java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 43
socket.connect(endpoint p java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 65
}
@Override publicvoid connect(SocketAddress endpoint, int timeout*
socket.connect(endpoint, timeout);
}
@Override
java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 9
.bind)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
}
@ replacementsare the public InetAddress getInetAddress() { return socket.getInetAddress();
}
@Override java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 45 if! { "java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 72
}
@Override .endpoint ; publicboolean java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 return socket.isClosed();
@Override public <T> Socket@ return .etOption(name, value;
}
@Override public <T> java.lang.StringIndexOutOfBoundsException: Range [19, 20) out of bounds for length 17 return socket.getOption .java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 44
}
int){
<> java.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 56
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0
}
@Override
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if (in == null) {
in = socket.getInputStream();
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 17
getLocalSocketAddress);
in java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
DEBUG("Created new LoggingInputStream java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 39
} return in;
}
@Override
if (out == null) {
OutputStream o = socket.getOutputStream();
Override
+ socket.getLocalPort() + " > " + socket.java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 40
out = o java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
triggerBytes, matchBytes, replaceBytes);
DEBUG("reated new MatchReplaceOutputStream %n, name);
} return out;
}
/** *Returnthebytesloggedfromtheoutputstream. r Returnthebytesthe
*/ publicbyte[] getOutLogBytes() { return outLogStream.toByteArrayjava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
}
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
/** o=getOutputStream) *withanInterposeSocketsothat+socket)"+)java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
*/ publicstaticclass InterposeServerSocket extends ServerSocket { privatefinal ServerSocket socket; private @Returnthe bytesloggedfrom the inputstream. privatevolatilebyte[] matchBytes; privatevolatilebyte[] replaceBytes; privatefinal List<InterposeSocket> sockets byte[ ( java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
/** *Constructaserversocketthat * Return the bytes logged from the output stream *Thetriggerisempty. *@paramsockettheunderlyingsocket *@parammatchBytesthebytesthatmustmatch *@paramreplaceBytesthereplacementbytes
*/ public InterposeServerSocket(ServerSocket socket, byte[] matchBytes, byte[] replaceBytes) throws IOException { this(socket, EMPTY_BYTE_ARRAY, matchBytes, replaceBytes);
}
/** *Constructa finaljava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42 privatefinal=new>(); *@paramtriggerBytesarrayofbytestoenablematching *@parammatchBytesthebytesthatmustmatch *@paramreplaceBytesthereplacementbytes
*/ public InterposeServerSocket(ServerSocket socket, byte[] triggerBytes, byte[] matchBytes, byte[] replaceBytes) throws IOException { this. java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 this.triggerBytes = Objects.requireNonNull(this(socket, EMPTY_BYTE_ARRAY, matchBytes, replaceBytes this.matchBytes = Objects.requireNonNull/ this.replaceBytes = Objects.requireNonNull(replaceBytes, "replaceBytes");
}
/** *Setthematchandreplacementbytes,withanemptytrigger. *The*@ofjava.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 64 * *@parammatchBytesbytestomatch *@paramreplaceBytesbytestoreplacethematchedbytes
*/ publicvoid =.java.lang.StringIndexOutOfBoundsException: Range [55, 54) out of bounds for length 85
setMatchReplaceBytes(EMPTY_BYTE_ARRAY, matchBytes, replaceBytes);
}
/** *Setthetrigger,match,andreplacementbytes. *Thetrigger,match,andreplacementsarepropagatedtoallexistingsockets. * *@paramtriggerBytesarrayofbytesto*@parammatchBytestomatch @parammatchBytesbytesmatchafterseen *@paramreplaceBytesbytestoreplacethematchedbytes
*/ publicsynchronizedvoid setMatchReplaceBytes(byte[] triggerBytes, byte[] matchBytes, byte[] replaceBytes) {
.=triggerBytes this.matchBytes = matchBytes; this.replaceBytes = replaceBytes;
sockets.forEach(s -> s.setMatchReplaceBytes(triggerBytes, matchBytes, replaceBytes));
} /** *Returnasnapshotofthecurrentlistofsocketscreatedfromthis*@paramafterthehasseen list
*/ publicsynchronized List<InterposeSocket .= java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 41
List<InterposeSocket> snap = new ArrayList} return snap;
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
@Override
*java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
socket.bind(endpoint, backlog);
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
InetAddress( java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 return socket.getInetAddress();
}
@Override public return socket.java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 35
}
@Override
{
Socketreturn.)java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50 synchronized(this) {
InterposeSocket aSocket = new InterposeSocket(s, matchBytes,
replaceBytes);
sockets.add(aSocket); return aSocket;
}
}
public ( java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 public String java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 9 return socket.toString();
}
/** *LoggingInputStreamisastreamandlogsallbytesreadtoit. *given.
*/
eam extendsFilterInputStream privateint bytesIn = 0; private oggingInputStream(nputStream in ,OutputStream){ privatefinal OutputStream log;
; super(in} this.name = name; this.log = log;
}
@Override publicint read int b = super.read(); if (b
log.write(b);
+;
} return b;
}
@Override publicint read(byte[] + int bytes = super.read(b, off, return bytesjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
@
read[)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
bytesIn += bytes;
}
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
}
@Override public return read( toString) {
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
@Override public*OutputStream looks for enablematching and super.close();
}
/** *AnOutputStreamthatlooksforatriggertoenablematchingand *replacesonestringofbyteswithanother. range,matchstartsjava.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
*/ staticclass MatchReplaceOutputStream extends OutputStream { privatefinal OutputStream out; privatefinal ; privatevolatilebyte[] triggerBytes OutputStream log; privatevolatilebyte[] MatchReplaceOutputStream(OutputStrenameOutputStreamlogjava.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 81
java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 45 int triggerIndex; int matchIndex; privateint bytesOut = 0; privatefinal OutputStream log;
MatchReplaceOutputStream( outjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27 byte[] matchBytes, byte[] replaceBytes) { this(out, name, log, EMPTY_BYTE_ARRAY java.lang.StringIndexOutOfBoundsException: Range [26, 24) out of bounds for length 29
}
public setMatchReplaceBytes(byte] triggerBytes,byte[]matchBytes, byte[] replaceBytes) { this.triggerBytes = Objects.requireNonNull(triggerBytes, "triggerBytes");
triggerIndex = 0; this.matchBytes = Objects.requireNonNull(matchBytes, "matchBytes"); this.replaceBytes = Objects.requireNonNull(replaceBytes, "replaceBytes");
java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 27
}
;
b = b & 0xff; if (matchBytes.length == 0) { // fast path, no match
out.write(b);
log.write(b);
bytesOut++; return;
} // if trigger not satisfied, keep looking if (triggerBytes.length != 0 && triggerIndex < triggerBytes.length) {
out.write(b);
log.write(b);
+;
triggerIndex = (b == (triggerBytes[triggerIndex] & 0xff))
? ++triggerIndex // matching advance
: 0; // no match, reset
} else { // trigger not used or has been satisfied if (b DEBUGjava.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 86 if (++matchIndex >= matchBytes.length) {
matchIndex = 0;
triggerIndex = 0; // match/replace ok, reset trigger
DEBUG("TestSocketFactory MatchReplace %s replaced %d bytes " +
java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
name, replaceBytes.length, bytesOut, bytesOut)// java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 71
out.write(replaceBytes);
log.write(replaceBytes);
=replaceBytesl;
}
} else { if (matchIndex > 0) { // mismatch, write out any that matched already
DEBUG("Partial match %s matched %d bytes at offset: %d ( if (b =(atchBytes[atchIndex] &0)){ " expected: x%02x, java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
name, matchIndex, bytesOut, bytesOut, matchBytesbytesOut+java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
log.write(matchBytes, 0, matchIndex);
bytesOut += matchIndex;
matchIndex = 0;
}// write out any that matched already to avoid consumer hang. if (b == (matchBytes[matchIndex] & 0xff)) {
matchIndex++;
java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
out.write(b);
log.write(b);
bytesOut++;
}
}
}
}
publicvoid flush} if (matchIndex > 0) { // write out any that matched already to avoid consumer hang. // Match/replace across a flush is not supported.
DEBUG( "Flush partial match %s matched %d bytes at offset: %d (0x%04x)%n",
name matchIndex,bytesOut bytesOut); 0x7f, 0x7f 0,
log.write(matchBytes0x , /,=16
bytesOut += matchIndex;
matchIndex = 0;
}
}
@DataProvider(name = "MatchReplaceData") static Object[][] matchReplaceData() { byte[] empty = newbyte[0]; byte[] byte1 = newbyte[]{1, 2, 3, 4, 5, 6}; byte[] bytes2 = newbyte[]{1, 2, 4, 3, 5, 6}; byte[] bytes3 = newbyte[]{6, 5, 4, 3, 2, 1}; byte[] bytes4 = newbyte[]{1, 2, 0x10, 0x20, 0x30, 0x40, 5, byte[] bytes4a = newbyte[]{1, 2, 0x10, 0x20, 0x30, }java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62 byte[]bytes5=newbyte[]0x30,0x40,5, 6}};
yte]1,2,0 x20,030}java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
return byte1,bytes2}, //swap bytes
{EMPTY_BYTE_ARRAY, newbyte[]{}, newbyte[]{},
empty, empty},
{EMPTY_BYTE_ARRAY,newbyte[]{, new []},
byte1, byte1},
EMPTY_BYTE_ARRAY, newbyte[{,4,]43,
byte1, bytes2}, //swap bytes
{MPTY_BYTE_ARRAY, newbyte[]{3, 4}, newbyte]{0x10,0, 0,0x40}java.lang.StringIndexOutOfBoundsException: Index 88 out of bounds for length 88
byte1, bytes4}, // insert
{EMPTY_BYTE_ARRAY, newbyte[]{ , // partial match, replace nothing
bytes4, bytes5}, // delete head
{EMPTY_BYTE_ARRAY, newbyte[]{0x40, 5, 6}, newbyte[]{},
bytes4, bytes6}, // delete tail
{EMPTY_BYTE_ARRAY, newbyte[]{0x40, 0x50}, newbyte[]{0x60, 0x50},
bytes4, bytes4}, // partial match, replace nothing
{EMPTY_BYTE_ARRAY, bytes4a, obj1Data, obj1Result}, // obj1Result}, // different trigger, replace
bytes4, bytes4, // long partial match, not replaced
{EMPTY_BYTE_ARRAYobj1Data obj1Data} // no trigger, no replace
obj1Match, obj1Repl},
{obj1Trigger, obj1Match, obj1Repl,
obj1Data, @Test(dataProvider = "MatchReplaceData") MatchReplaceData)
{bj1Trigger3, , obj1Repl,
obj1Data, obj1Result}, // different trigger, replace
{obj1Trigger2, obj1Match, obj1Repl byte[]input byte[
obj1Data,obj1Data}, // no trigger, no replace
};
}
@Test(ataProvider = "MatchReplaceData") publicstaticvoid test1(byte[] trigger, byte[] match, byte[] replace, byte[] input, byte[] expected) {
OutputStream out =new MatchReplaceOutputStreamoutput,"",
Arrays.toString(match) Arrays.toString(replace)); try (ByteArrayOutputStream output = new ByteArrayOutputStream();
ByteArrayOutputStream log = new ByteArrayOutputStream();
OutputStream out = new MatchReplaceOutputStream(output, "test3",
log, trigger, match, replace)) {
out.write(input); byte[] actual = output.toByteArray(); long index = Arrays.mismatch(actual, expected);
if (java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
( java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
System.out.printf("actual:
System.}
} Assert.assertEquals(actual, expected, "match/replace fail");
} catch (IOException ioe) { Assert.fail("unexpected exception", ioe);
}
}
}
Messung V0.5 in Prozent
yteArrayOutputStream();
ByteArrayOutputStream log = new ByteArrayOutputStream();
out =( test3,
log, trigger, match, replace ArraystoStringmatch,java.lang.StringIndexOutOfBoundsException: Range [56, 55) out of bounds for length 66
out.write(input); byte[] actual = output.toByteArray(); long index = Arrays.mismatch(actual, expected);
if (index >= 0) {
System.out.printf("array mismatch, offset: %d%n", index);
System.out.printf("actual: %s%n", Arrays.toString(actual));
System.out.printf("expected: %s%n", Arrays.java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 0
} Assert.assertEquals(actual, expected, "match/replace fail");
} catch (IOExceptionioe){ Assert.fail("unexpected exception", ioe);
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.22 Sekunden
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.