Merge
authorjwilhelm
Tue, 29 Aug 2017 22:15:40 +0200
changeset 47120 ae1d29b6937f
parent 47119 e28c8b19ffb2 (diff)
parent 47118 10283559cc3c (current diff)
child 47121 3aceb4fc0e84
child 47122 09e99b01bb6e
Merge
--- a/jdk/src/java.base/share/classes/java/text/NumberFormat.java	Mon Aug 28 21:46:12 2017 +0200
+++ b/jdk/src/java.base/share/classes/java/text/NumberFormat.java	Tue Aug 29 22:15:40 2017 +0200
@@ -181,6 +181,17 @@
  * The subclass may provide its own implementation and specification about
  * {@code NullPointerException}.
  *
+ * <p>
+ * The default implementation provides rounding modes defined
+ * in {@link java.math.RoundingMode} for formatting numbers. It
+ * uses the {@linkplain java.math.RoundingMode#HALF_EVEN
+ * round half-even algorithm}. To change the rounding mode use
+ * {@link #setRoundingMode(java.math.RoundingMode) setRoundingMode}.
+ * The {@code NumberFormat} returned by the static factory methods is
+ * configured to round floating point numbers using half-even
+ * rounding (see {@link java.math.RoundingMode#HALF_EVEN
+ * RoundingMode.HALF_EVEN}) for formatting.
+ *
  * @see          DecimalFormat
  * @see          ChoiceFormat
  * @author       Mark Davis
--- a/jdk/src/java.base/share/classes/java/time/chrono/HijrahEra.java	Mon Aug 28 21:46:12 2017 +0200
+++ b/jdk/src/java.base/share/classes/java/time/chrono/HijrahEra.java	Tue Aug 29 22:15:40 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2017, 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
@@ -64,10 +64,13 @@
 import static java.time.temporal.ChronoField.ERA;
 
 import java.time.DateTimeException;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.TextStyle;
 import java.time.temporal.ChronoField;
 import java.time.temporal.TemporalField;
 import java.time.temporal.UnsupportedTemporalTypeException;
 import java.time.temporal.ValueRange;
+import java.util.Locale;
 
 /**
  * An era in the Hijrah calendar system.
@@ -155,4 +158,18 @@
         return Era.super.range(field);
     }
 
+    /**
+     * {@inheritDoc}
+     *
+     * @param style {@inheritDoc}
+     * @param locale {@inheritDoc}
+     */
+    @Override
+    public String getDisplayName(TextStyle style, Locale locale) {
+        return new DateTimeFormatterBuilder()
+            .appendText(ERA, style)
+            .toFormatter(locale)
+            .withChronology(HijrahChronology.INSTANCE)
+            .format(HijrahDate.now());
+    }
 }
--- a/jdk/src/java.base/share/classes/java/time/chrono/JapaneseEra.java	Mon Aug 28 21:46:12 2017 +0200
+++ b/jdk/src/java.base/share/classes/java/time/chrono/JapaneseEra.java	Tue Aug 29 22:15:40 2017 +0200
@@ -73,6 +73,7 @@
 import java.io.Serializable;
 import java.time.DateTimeException;
 import java.time.LocalDate;
+import java.time.format.DateTimeFormatterBuilder;
 import java.time.format.TextStyle;
 import java.time.temporal.ChronoField;
 import java.time.temporal.TemporalField;
@@ -253,7 +254,12 @@
             Objects.requireNonNull(locale, "locale");
             return style.asNormal() == TextStyle.NARROW ? getAbbreviation() : getName();
         }
-        return Era.super.getDisplayName(style, locale);
+
+        return new DateTimeFormatterBuilder()
+            .appendText(ERA, style)
+            .toFormatter(locale)
+            .withChronology(JapaneseChronology.INSTANCE)
+            .format(this == MEIJI ? MEIJI_6_ISODATE : since);
     }
 
     //-----------------------------------------------------------------------
--- a/jdk/src/java.base/share/classes/java/time/chrono/MinguoEra.java	Mon Aug 28 21:46:12 2017 +0200
+++ b/jdk/src/java.base/share/classes/java/time/chrono/MinguoEra.java	Tue Aug 29 22:15:40 2017 +0200
@@ -61,7 +61,12 @@
  */
 package java.time.chrono;
 
+import static java.time.temporal.ChronoField.ERA;
+
 import java.time.DateTimeException;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.TextStyle;
+import java.util.Locale;
 
 /**
  * An era in the Minguo calendar system.
@@ -153,4 +158,19 @@
         return ordinal();
     }
 
+    /**
+     * {@inheritDoc}
+     *
+     * @param style {@inheritDoc}
+     * @param locale {@inheritDoc}
+     */
+    @Override
+    public String getDisplayName(TextStyle style, Locale locale) {
+        return new DateTimeFormatterBuilder()
+            .appendText(ERA, style)
+            .toFormatter(locale)
+            .withChronology(MinguoChronology.INSTANCE)
+            .format(this == ROC ? MinguoDate.of(1, 1, 1) : MinguoDate.of(0, 1, 1));
+    }
+
 }
--- a/jdk/src/java.base/share/classes/java/time/chrono/ThaiBuddhistEra.java	Mon Aug 28 21:46:12 2017 +0200
+++ b/jdk/src/java.base/share/classes/java/time/chrono/ThaiBuddhistEra.java	Tue Aug 29 22:15:40 2017 +0200
@@ -61,7 +61,12 @@
  */
 package java.time.chrono;
 
+import static java.time.temporal.ChronoField.ERA;
+
 import java.time.DateTimeException;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.TextStyle;
+import java.util.Locale;
 
 /**
  * An era in the Thai Buddhist calendar system.
@@ -153,4 +158,19 @@
         return ordinal();
     }
 
+    /**
+     * {@inheritDoc}
+     *
+     * @param style {@inheritDoc}
+     * @param locale {@inheritDoc}
+     */
+    @Override
+    public String getDisplayName(TextStyle style, Locale locale) {
+        return new DateTimeFormatterBuilder()
+            .appendText(ERA, style)
+            .toFormatter(locale)
+            .withChronology(ThaiBuddhistChronology.INSTANCE)
+            .format(this == BE ? ThaiBuddhistDate.of(1, 1, 1) : ThaiBuddhistDate.of(0, 1, 1));
+    }
+
 }
--- a/jdk/src/java.base/share/classes/java/util/Formatter.java	Mon Aug 28 21:46:12 2017 +0200
+++ b/jdk/src/java.base/share/classes/java/util/Formatter.java	Tue Aug 29 22:15:40 2017 +0200
@@ -1229,7 +1229,7 @@
  *     than the number of digits which would appear after the decimal point in
  *     the string returned by {@link Float#toString(float)} or {@link
  *     Double#toString(double)} respectively, then the value will be rounded
- *     using the {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
+ *     using the {@linkplain java.math.RoundingMode#HALF_UP round half up
  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
  *     For a canonical representation of the value, use {@link
  *     Float#toString(float)} or {@link Double#toString(double)} as
@@ -1298,7 +1298,7 @@
  *     than the number of digits which would appear after the decimal point in
  *     the string returned by {@link Float#toString(float)} or {@link
  *     Double#toString(double)} respectively, then the value will be rounded
- *     using the {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
+ *     using the {@linkplain java.math.RoundingMode#HALF_UP round half up
  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
  *     For a canonical representation of the value, use {@link
  *     Float#toString(float)} or {@link Double#toString(double)} as
@@ -1461,7 +1461,7 @@
  *     specified then the default value is {@code 6}.  If the precision is
  *     less than the number of digits to the right of the decimal point then
  *     the value will be rounded using the
- *     {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
+ *     {@linkplain java.math.RoundingMode#HALF_UP round half up
  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
  *     For a canonical representation of the value, use {@link
  *     BigDecimal#toString()}.
@@ -1524,7 +1524,7 @@
  *     specified then the default value is {@code 6}.  If the precision is
  *     less than the number of digits to the right of the decimal point
  *     then the value will be rounded using the
- *     {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
+ *     {@linkplain java.math.RoundingMode#HALF_UP round half up
  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
  *     For a canonical representation of the value, use {@link
  *     BigDecimal#toString()}.
--- a/jdk/src/java.base/share/classes/javax/net/ssl/SSLEngineResult.java	Mon Aug 28 21:46:12 2017 +0200
+++ b/jdk/src/java.base/share/classes/javax/net/ssl/SSLEngineResult.java	Tue Aug 29 22:15:40 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2017, 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
@@ -213,7 +213,7 @@
      *
      * @param   sequenceNumber
      *          the sequence number (unsigned long) of the produced or
-     *          consumed SSL/TLS/DTLS record, or ${@code -1L} if no record
+     *          consumed SSL/TLS/DTLS record, or {@code -1L} if no record
      *          produced or consumed
      *
      * @throws  IllegalArgumentException
@@ -299,7 +299,7 @@
      *           implementation.
      *
      * @return  the sequence number of the produced or consumed SSL/TLS/DTLS
-     *          record; or ${@code -1L} if no record is produced or consumed,
+     *          record; or {@code -1L} if no record is produced or consumed,
      *          or this operation is not supported by the underlying provider
      *
      * @see     java.lang.Long#compareUnsigned(long, long)
--- a/jdk/test/java/rmi/testlibrary/TestSocketFactory.java	Mon Aug 28 21:46:12 2017 +0200
+++ b/jdk/test/java/rmi/testlibrary/TestSocketFactory.java	Tue Aug 29 22:15:40 2017 +0200
@@ -45,20 +45,43 @@
 import java.util.Set;
 
 import org.testng.Assert;
-import org.testng.TestNG;
 import org.testng.annotations.Test;
 import org.testng.annotations.DataProvider;
 
+/*
+ * @test
+ * @summary TestSocket Factory and tests of the basic trigger, match, and replace functions
+ * @run testng TestSocketFactory
+ * @bug 8186539
+ */
 
 /**
  * A RMISocketFactory utility factory to log RMI stream contents and to
- * match and replace output stream contents to simulate failures.
+ * trigger, and then match and replace output stream contents to simulate failures.
+ * <p>
+ * The trigger is a sequence of bytes that must be found before looking
+ * for the bytes to match and replace.  If the trigger sequence is empty
+ * matching is immediately enabled. While waiting for the trigger to be found
+ * bytes written to the streams are written through to the output stream.
+ * The when triggered and when a trigger is non-empty, matching looks for
+ * the sequence of bytes supplied.  If the sequence is empty, no matching or
+ * replacement is performed.
+ * While waiting for a complete match, the partial matched bytes are not
+ * written to the output stream.  When the match is incomplete, the partial
+ * matched bytes are written to the output.  When a match is complete the
+ * full replacement byte array is written to the output.
+ * <p>
+ * The trigger, match, and replacement bytes arrays can be changed at any
+ * time and immediately reset and restart matching.  Changes are propagated
+ * to all of the sockets created from the factories immediately.
  */
 public class TestSocketFactory extends RMISocketFactory
         implements RMIClientSocketFactory, RMIServerSocketFactory, Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    private volatile transient byte[] triggerBytes;
+
     private volatile transient byte[] matchBytes;
 
     private volatile transient byte[] replaceBytes;
@@ -67,6 +90,8 @@
 
     private transient final List<InterposeServerSocket> serverSockets = new ArrayList<>();
 
+    static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+
     public static final boolean DEBUG = false;
 
     /**
@@ -82,28 +107,51 @@
     }
 
     /**
-     * Create a socket factory that creates InputStreams that log
-     * and OutputStreams that log .
+     * Create a socket factory that creates InputStreams
+     * and OutputStreams that log.
      */
     public TestSocketFactory() {
-        this.matchBytes = new byte[0];
-        this.replaceBytes = this.matchBytes;
-        System.out.printf("Creating TestSocketFactory()%n");
+        this.triggerBytes = EMPTY_BYTE_ARRAY;
+        this.matchBytes = EMPTY_BYTE_ARRAY;
+        this.replaceBytes = EMPTY_BYTE_ARRAY;
+    }
+
+    /**
+     * Set the match and replacement bytes, with an empty trigger.
+     * The match and replacements are propagated to all existing sockets.
+     *
+     * @param matchBytes bytes to match
+     * @param replaceBytes bytes to replace the matched bytes
+     */
+    public void setMatchReplaceBytes(byte[] matchBytes, byte[] replaceBytes) {
+        setMatchReplaceBytes(EMPTY_BYTE_ARRAY, matchBytes, replaceBytes);
     }
 
-    public void setMatchReplaceBytes(byte[] matchBytes, byte[] replaceBytes) {
+    /**
+     * Set the trigger, match, and replacement bytes.
+     * The trigger, match, and replacements are propagated to all existing sockets.
+     *
+     * @param triggerBytes array of bytes to use as a trigger, may be zero length
+     * @param matchBytes bytes to match after the trigger has been seen
+     * @param replaceBytes bytes to replace the matched bytes
+     */
+    public void setMatchReplaceBytes(byte[] triggerBytes, byte[] matchBytes,
+                                     byte[] replaceBytes) {
+        this.triggerBytes = Objects.requireNonNull(triggerBytes, "triggerBytes");
         this.matchBytes = Objects.requireNonNull(matchBytes, "matchBytes");
         this.replaceBytes = Objects.requireNonNull(replaceBytes, "replaceBytes");
-        sockets.forEach( s -> s.setMatchReplaceBytes(matchBytes, replaceBytes));
-        serverSockets.forEach( s -> s.setMatchReplaceBytes(matchBytes, replaceBytes));
-
+        sockets.forEach( s -> s.setMatchReplaceBytes(triggerBytes, matchBytes,
+                replaceBytes));
+        serverSockets.forEach( s -> s.setMatchReplaceBytes(triggerBytes, matchBytes,
+                replaceBytes));
     }
 
     @Override
     public Socket createSocket(String host, int port) throws IOException {
         Socket socket = RMISocketFactory.getDefaultSocketFactory()
                 .createSocket(host, port);
-        InterposeSocket s = new InterposeSocket(socket, matchBytes, replaceBytes);
+        InterposeSocket s = new InterposeSocket(socket,
+                triggerBytes, matchBytes, replaceBytes);
         sockets.add(s);
         return s;
     }
@@ -122,7 +170,8 @@
 
         ServerSocket serverSocket = RMISocketFactory.getDefaultSocketFactory()
                 .createServerSocket(port);
-        InterposeServerSocket ss = new InterposeServerSocket(serverSocket, matchBytes, replaceBytes);
+        InterposeServerSocket ss = new InterposeServerSocket(serverSocket,
+                triggerBytes, matchBytes, replaceBytes);
         serverSockets.add(ss);
         return ss;
     }
@@ -139,13 +188,15 @@
     /**
      * An InterposeSocket wraps a socket that produces InputStreams
      * and OutputStreams that log the traffic.
-     * The OutputStreams it produces match an array of bytes and replace them.
+     * The OutputStreams it produces watch for a trigger and then
+     * match an array of bytes and replace them.
      * Useful for injecting protocol and content errors.
      */
     public static class InterposeSocket extends Socket {
         private final Socket socket;
         private InputStream in;
         private MatchReplaceOutputStream out;
+        private volatile byte[] triggerBytes;
         private volatile byte[] matchBytes;
         private volatile byte[] replaceBytes;
         private final ByteArrayOutputStream inLogStream;
@@ -153,8 +204,28 @@
         private final String name;
         private static volatile int num = 0;    // index for created InterposeSockets
 
+        /**
+         * Construct a socket that interposes on a socket to match and replace.
+         * The trigger is empty.
+         * @param socket the underlying socket
+         * @param matchBytes the bytes that must match
+         * @param replaceBytes the replacement bytes
+         */
         public InterposeSocket(Socket socket, byte[] matchBytes, byte[] replaceBytes) {
+            this(socket, EMPTY_BYTE_ARRAY, matchBytes, replaceBytes);
+        }
+
+        /**
+         * Construct a socket that interposes on a socket to match and replace.
+         * @param socket the underlying socket
+         * @param triggerBytes array of bytes to enable matching
+         * @param matchBytes the bytes that must match
+         * @param replaceBytes the replacement bytes
+         */
+        public InterposeSocket(Socket socket, byte[]
+                triggerBytes, byte[] matchBytes, byte[] replaceBytes) {
             this.socket = socket;
+            this.triggerBytes = Objects.requireNonNull(triggerBytes, "triggerBytes");
             this.matchBytes = Objects.requireNonNull(matchBytes, "matchBytes");
             this.replaceBytes = Objects.requireNonNull(replaceBytes, "replaceBytes");
             this.inLogStream = new ByteArrayOutputStream();
@@ -164,10 +235,32 @@
                     + socket.getLocalPort() + " <  " + socket.getPort();
         }
 
+        /**
+         * Set the match and replacement bytes, with an empty trigger.
+         * The match and replacements are propagated to all existing sockets.
+         *
+         * @param matchBytes bytes to match
+         * @param replaceBytes bytes to replace the matched bytes
+         */
         public void setMatchReplaceBytes(byte[] matchBytes, byte[] replaceBytes) {
+            this.setMatchReplaceBytes(EMPTY_BYTE_ARRAY, matchBytes, replaceBytes);
+        }
+
+        /**
+         * Set the trigger, match, and replacement bytes.
+         * The trigger, match, and replacements are propagated to the
+         * MatchReplaceOutputStream.
+         *
+         * @param triggerBytes array of bytes to use as a trigger, may be zero length
+         * @param matchBytes bytes to match after the trigger has been seen
+         * @param replaceBytes bytes to replace the matched bytes
+         */
+        public void setMatchReplaceBytes(byte[] triggerBytes, byte[] matchBytes,
+                                         byte[] replaceBytes) {
+            this.triggerBytes = triggerBytes;
             this.matchBytes = matchBytes;
             this.replaceBytes = replaceBytes;
-            out.setMatchReplaceBytes(matchBytes, replaceBytes);
+            out.setMatchReplaceBytes(triggerBytes, matchBytes, replaceBytes);
         }
 
         @Override
@@ -278,7 +371,8 @@
                 OutputStream o = socket.getOutputStream();
                 String name = Thread.currentThread().getName() + ": "
                         + socket.getLocalPort() + "  > " + socket.getPort();
-                out = new MatchReplaceOutputStream(o, name, outLogStream, matchBytes, replaceBytes);
+                out = new MatchReplaceOutputStream(o, name, outLogStream,
+                        triggerBytes, matchBytes, replaceBytes);
                 DEBUG("Created new MatchReplaceOutputStream: %s%n", name);
             }
             return out;
@@ -308,20 +402,63 @@
      */
     public static class InterposeServerSocket extends ServerSocket {
         private final ServerSocket socket;
+        private volatile byte[] triggerBytes;
         private volatile byte[] matchBytes;
         private volatile byte[] replaceBytes;
         private final List<InterposeSocket> sockets = new ArrayList<>();
 
-        public InterposeServerSocket(ServerSocket socket, byte[] matchBytes, byte[] replaceBytes) throws IOException {
+        /**
+         * Construct a server socket that interposes on a socket to match and replace.
+         * The trigger is empty.
+         * @param socket the underlying socket
+         * @param matchBytes the bytes that must match
+         * @param replaceBytes the replacement bytes
+         */
+        public InterposeServerSocket(ServerSocket socket, byte[] matchBytes,
+                                     byte[] replaceBytes) throws IOException {
+            this(socket, EMPTY_BYTE_ARRAY, matchBytes, replaceBytes);
+        }
+
+        /**
+         * Construct a server socket that interposes on a socket to match and replace.
+         * @param socket the underlying socket
+         * @param triggerBytes array of bytes to enable matching
+         * @param matchBytes the bytes that must match
+         * @param replaceBytes the replacement bytes
+         */
+        public InterposeServerSocket(ServerSocket socket, byte[] triggerBytes,
+                                     byte[] matchBytes, byte[] replaceBytes) throws IOException {
             this.socket = socket;
+            this.triggerBytes = Objects.requireNonNull(triggerBytes, "triggerBytes");
             this.matchBytes = Objects.requireNonNull(matchBytes, "matchBytes");
             this.replaceBytes = Objects.requireNonNull(replaceBytes, "replaceBytes");
         }
 
+        /**
+         * Set the match and replacement bytes, with an empty trigger.
+         * The match and replacements are propagated to all existing sockets.
+         *
+         * @param matchBytes bytes to match
+         * @param replaceBytes bytes to replace the matched bytes
+         */
         public void setMatchReplaceBytes(byte[] matchBytes, byte[] replaceBytes) {
+            setMatchReplaceBytes(EMPTY_BYTE_ARRAY, matchBytes, replaceBytes);
+        }
+
+        /**
+         * Set the trigger, match, and replacement bytes.
+         * The trigger, match, and replacements are propagated to all existing sockets.
+         *
+         * @param triggerBytes array of bytes to use as a trigger, may be zero length
+         * @param matchBytes bytes to match after the trigger has been seen
+         * @param replaceBytes bytes to replace the matched bytes
+         */
+        public void setMatchReplaceBytes(byte[] triggerBytes, byte[] matchBytes,
+                                         byte[] replaceBytes) {
+            this.triggerBytes = triggerBytes;
             this.matchBytes = matchBytes;
             this.replaceBytes = replaceBytes;
-            sockets.forEach(s -> s.setMatchReplaceBytes(matchBytes, replaceBytes));
+            sockets.forEach(s -> s.setMatchReplaceBytes(triggerBytes, matchBytes, replaceBytes));
         }
         /**
          * Return a snapshot of the current list of sockets created from this server socket.
@@ -386,7 +523,8 @@
         }
 
         @Override
-        public <T> ServerSocket setOption(SocketOption<T> name, T value) throws IOException {
+        public <T> ServerSocket setOption(SocketOption<T> name, T value)
+                throws IOException {
             return socket.setOption(name, value);
         }
 
@@ -463,22 +601,33 @@
     }
 
     /**
-     * An OutputStream that replaces one string of bytes with another.
+     * An OutputStream that looks for a trigger to enable matching and
+     * replaces one string of bytes with another.
      * If any range matches, the match starts after the partial match.
      */
     static class MatchReplaceOutputStream extends OutputStream {
         private final OutputStream out;
         private final String name;
+        private volatile byte[] triggerBytes;
         private volatile byte[] matchBytes;
         private volatile byte[] replaceBytes;
+        int triggerIndex;
         int matchIndex;
         private int bytesOut = 0;
         private final OutputStream log;
 
         MatchReplaceOutputStream(OutputStream out, String name, OutputStream log,
                                  byte[] matchBytes, byte[] replaceBytes) {
+            this(out, name, log, EMPTY_BYTE_ARRAY, matchBytes, replaceBytes);
+        }
+
+        MatchReplaceOutputStream(OutputStream out, String name, OutputStream log,
+                                 byte[] triggerBytes, byte[] matchBytes,
+                                 byte[] replaceBytes) {
             this.out = out;
             this.name = name;
+            this.triggerBytes = Objects.requireNonNull(triggerBytes, "triggerBytes");
+            triggerIndex = 0;
             this.matchBytes = Objects.requireNonNull(matchBytes, "matchBytes");
             this.replaceBytes = Objects.requireNonNull(replaceBytes, "replaceBytes");
             matchIndex = 0;
@@ -486,8 +635,15 @@
         }
 
         public void setMatchReplaceBytes(byte[] matchBytes, byte[] replaceBytes) {
-            this.matchBytes = matchBytes;
-            this.replaceBytes = replaceBytes;
+            setMatchReplaceBytes(EMPTY_BYTE_ARRAY, matchBytes, replaceBytes);
+        }
+
+        public void 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");
             matchIndex = 0;
         }
 
@@ -495,36 +651,52 @@
         public void write(int b) throws IOException {
             b = b & 0xff;
             if (matchBytes.length == 0) {
+                // fast path, no match
                 out.write(b);
                 log.write(b);
                 bytesOut++;
                 return;
             }
-            if (b == (matchBytes[matchIndex] & 0xff)) {
-                if (++matchIndex >= matchBytes.length) {
-                    matchIndex = 0;
-                    DEBUG( "TestSocketFactory MatchReplace %s replaced %d bytes at offset: %d (x%04x)%n",
-                            name, replaceBytes.length, bytesOut, bytesOut);
-                    out.write(replaceBytes);
-                    log.write(replaceBytes);
-                    bytesOut += replaceBytes.length;
-                }
+            // if trigger not satisfied, keep looking
+            if (triggerBytes.length != 0 && triggerIndex < triggerBytes.length) {
+                out.write(b);
+                log.write(b);
+                bytesOut++;
+
+                triggerIndex = (b == (triggerBytes[triggerIndex] & 0xff))
+                        ? ++triggerIndex    // matching advance
+                        : 0;                // no match, reset
             } else {
-                if (matchIndex > 0) {
-                    // mismatch, write out any that matched already
-                    DEBUG("Partial match %s matched %d bytes at offset: %d (0x%04x), expected: x%02x, actual: x%02x%n",
-                            name, matchIndex, bytesOut, bytesOut, matchBytes[matchIndex], b);
-                    out.write(matchBytes, 0, matchIndex);
-                    log.write(matchBytes, 0, matchIndex);
-                    bytesOut += matchIndex;
-                    matchIndex = 0;
-                }
+                // trigger not used or has been satisfied
                 if (b == (matchBytes[matchIndex] & 0xff)) {
-                    matchIndex++;
+                    if (++matchIndex >= matchBytes.length) {
+                        matchIndex = 0;
+                        triggerIndex = 0;       // match/replace ok, reset trigger
+                        DEBUG("TestSocketFactory MatchReplace %s replaced %d bytes " +
+                                "at offset: %d (x%04x)%n",
+                                name, replaceBytes.length, bytesOut, bytesOut);
+                        out.write(replaceBytes);
+                        log.write(replaceBytes);
+                        bytesOut += replaceBytes.length;
+                    }
                 } else {
-                    out.write(b);
-                    log.write(b);
-                    bytesOut++;
+                    if (matchIndex > 0) {
+                        // mismatch, write out any that matched already
+                        DEBUG("Partial match %s matched %d bytes at offset: %d (0x%04x), " +
+                                " expected: x%02x, actual: x%02x%n",
+                                name, matchIndex, bytesOut, bytesOut, matchBytes[matchIndex], b);
+                        out.write(matchBytes, 0, matchIndex);
+                        log.write(matchBytes, 0, matchIndex);
+                        bytesOut += matchIndex;
+                        matchIndex = 0;
+                    }
+                    if (b == (matchBytes[matchIndex] & 0xff)) {
+                        matchIndex++;
+                    } else {
+                        out.write(b);
+                        log.write(b);
+                        bytesOut++;
+                    }
                 }
             }
         }
@@ -548,18 +720,44 @@
         }
     }
 
-    private static byte[] orig = new byte[]{
+    private static byte[] obj1Data = new byte[] {
+            0x7e, 0x7e, 0x7e,
             (byte) 0x80, 0x05,
-            0x73, 0x72, 0x00, 0x12, // TC_OBJECT, TC_CLASSDESC, length = 18
-            0x6A, 0x61, 0x76, 0x61, 0x2E, 0x72, 0x6D, 0x69, 0x2E, // "java.rmi."
-            0x64, 0x67, 0x63, 0x2E, 0x4C, 0x65, 0x61, 0x73, 0x65  // "dgc.Lease"
+            0x7f, 0x7f, 0x7f,
+            0x73, 0x72, 0x00, 0x10, // TC_OBJECT, TC_CLASSDESC, length = 16
+            (byte)'j', (byte)'a', (byte)'v', (byte)'a', (byte)'.',
+            (byte)'l', (byte)'a', (byte)'n', (byte)'g', (byte)'.',
+            (byte)'n', (byte)'u', (byte)'m', (byte)'b', (byte)'e', (byte)'r'
+    };
+    private static byte[] obj1Result = new byte[] {
+            0x7e, 0x7e, 0x7e,
+            (byte) 0x80, 0x05,
+            0x7f, 0x7f, 0x7f,
+            0x73, 0x72, 0x00, 0x11, // TC_OBJECT, TC_CLASSDESC, length = 17
+            (byte)'j', (byte)'a', (byte)'v', (byte)'a', (byte)'.',
+            (byte)'l', (byte)'a', (byte)'n', (byte)'g', (byte)'.',
+            (byte)'I', (byte)'n', (byte)'t', (byte)'e', (byte)'g', (byte)'e', (byte)'r'
     };
-    private static byte[] repl = new byte[]{
-            (byte) 0x80, 0x05,
-            0x73, 0x72, 0x00, 0x12, // TC_OBJECT, TC_CLASSDESC, length = 18
-            0x6A, 0x61, 0x76, 0x61, 0x2E, (byte) 'l', (byte) 'a', (byte) 'n', (byte) 'g',
-            0x2E, (byte) 'R', (byte) 'u', (byte) 'n', (byte) 'n', (byte) 'a', (byte) 'b', (byte) 'l',
-            (byte) 'e'
+    private static byte[] obj1Trigger = new byte[] {
+            (byte) 0x80, 0x05
+    };
+    private static byte[] obj1Trigger2 = new byte[] {
+            0x7D, 0x7D, 0x7D, 0x7D,
+    };
+    private static byte[] obj1Trigger3 = new byte[] {
+            0x7F,
+    };
+    private static byte[] obj1Match = new byte[] {
+            0x73, 0x72, 0x00, 0x10, // TC_OBJECT, TC_CLASSDESC, length = 16
+            (byte)'j', (byte)'a', (byte)'v', (byte)'a', (byte)'.',
+            (byte)'l', (byte)'a', (byte)'n', (byte)'g', (byte)'.',
+            (byte)'n', (byte)'u', (byte)'m', (byte)'b', (byte)'e', (byte)'r'
+    };
+    private static byte[] obj1Repl = new byte[] {
+            0x73, 0x72, 0x00, 0x11, // TC_OBJECT, TC_CLASSDESC, length = 17
+            (byte)'j', (byte)'a', (byte)'v', (byte)'a', (byte)'.',
+            (byte)'l', (byte)'a', (byte)'n', (byte)'g', (byte)'.',
+            (byte)'I', (byte)'n', (byte)'t', (byte)'e', (byte)'g', (byte)'e', (byte)'r'
     };
 
     @DataProvider(name = "MatchReplaceData")
@@ -574,26 +772,42 @@
         byte[] bytes6 = new byte[]{1, 2, 0x10, 0x20, 0x30};
 
         return new Object[][]{
-                {new byte[]{}, new byte[]{}, empty, empty},
-                {new byte[]{}, new byte[]{}, byte1, byte1},
-                {new byte[]{3, 4}, new byte[]{4, 3}, byte1, bytes2}, //swap bytes
-                {new byte[]{3, 4}, new byte[]{0x10, 0x20, 0x30, 0x40}, byte1, bytes4}, // insert
-                {new byte[]{1, 2, 0x10, 0x20}, new byte[]{}, bytes4, bytes5}, // delete head
-                {new byte[]{0x40, 5, 6}, new byte[]{}, bytes4, bytes6},   // delete tail
-                {new byte[]{0x40, 0x50}, new byte[]{0x60, 0x50}, bytes4, bytes4}, // partial match, replace nothing
-                {bytes4a, bytes3, bytes4, bytes4}, // long partial match, not replaced
-                {orig, repl, orig, repl},
+                {EMPTY_BYTE_ARRAY, new byte[]{}, new byte[]{},
+                        empty, empty},
+                {EMPTY_BYTE_ARRAY, new byte[]{}, new byte[]{},
+                        byte1, byte1},
+                {EMPTY_BYTE_ARRAY, new byte[]{3, 4}, new byte[]{4, 3},
+                        byte1, bytes2}, //swap bytes
+                {EMPTY_BYTE_ARRAY, new byte[]{3, 4}, new byte[]{0x10, 0x20, 0x30, 0x40},
+                        byte1, bytes4}, // insert
+                {EMPTY_BYTE_ARRAY, new byte[]{1, 2, 0x10, 0x20}, new byte[]{},
+                        bytes4, bytes5}, // delete head
+                {EMPTY_BYTE_ARRAY, new byte[]{0x40, 5, 6}, new byte[]{},
+                        bytes4, bytes6},   // delete tail
+                {EMPTY_BYTE_ARRAY, new byte[]{0x40, 0x50}, new byte[]{0x60, 0x50},
+                        bytes4, bytes4}, // partial match, replace nothing
+                {EMPTY_BYTE_ARRAY, bytes4a, bytes3,
+                        bytes4, bytes4}, // long partial match, not replaced
+                {EMPTY_BYTE_ARRAY, obj1Match, obj1Repl,
+                        obj1Match, obj1Repl},
+                {obj1Trigger, obj1Match, obj1Repl,
+                        obj1Data, obj1Result},
+                {obj1Trigger3, obj1Match, obj1Repl,
+                        obj1Data, obj1Result}, // different trigger, replace
+                {obj1Trigger2, obj1Match, obj1Repl,
+                        obj1Data, obj1Data},  // no trigger, no replace
         };
     }
 
-    @Test(enabled = true, dataProvider = "MatchReplaceData")
-    static void test3(byte[] match, byte[] replace,
+    @Test(dataProvider = "MatchReplaceData")
+    public static void test1(byte[] trigger, byte[] match, byte[] replace,
                       byte[] input, byte[] expected) {
-        System.out.printf("match: %s, replace: %s%n", Arrays.toString(match), Arrays.toString(replace));
+        System.out.printf("trigger: %s, match: %s, replace: %s%n", Arrays.toString(trigger),
+                Arrays.toString(match), Arrays.toString(replace));
         try (ByteArrayOutputStream output = new ByteArrayOutputStream();
         ByteArrayOutputStream log = new ByteArrayOutputStream();
              OutputStream out = new MatchReplaceOutputStream(output, "test3",
-                     log, match, replace)) {
+                     log, trigger, match, replace)) {
             out.write(input);
             byte[] actual = output.toByteArray();
             long index = Arrays.mismatch(actual, expected);
@@ -608,7 +822,4 @@
             Assert.fail("unexpected exception", ioe);
         }
     }
-
-
-
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/time/test/java/time/chrono/TestEraDisplayName.java	Tue Aug 29 22:15:40 2017 +0200
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2017, 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 test.java.time.chrono;
+
+import java.time.*;
+import java.time.chrono.*;
+import java.time.format.*;
+import java.util.Locale;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+
+/**
+ * Tests Era.getDisplayName() correctly returns the name based on each
+ * chrono implementation.
+ * Note: The exact result may depend on locale data provider's implementation.
+ *
+ * @bug 8171049
+ */
+@Test
+public class TestEraDisplayName {
+    private static final Locale THAI = Locale.forLanguageTag("th-TH");
+    private static final Locale EGYPT = Locale.forLanguageTag("ar-EG");
+
+    @DataProvider(name="eraDisplayName")
+    Object[][] eraDisplayName() {
+        return new Object[][] {
+            // Era, text style, displyay locale, expected name
+            // IsoEra
+            { IsoEra.BCE,   TextStyle.FULL,     Locale.US,      "Before Christ" },
+            { IsoEra.CE,    TextStyle.FULL,     Locale.US,      "Anno Domini" },
+            { IsoEra.BCE,   TextStyle.FULL,     Locale.JAPAN,   "\u7d00\u5143\u524d" },
+            { IsoEra.CE,    TextStyle.FULL,     Locale.JAPAN,   "\u897f\u66a6" },
+            { IsoEra.BCE,   TextStyle.SHORT,    Locale.US,      "BC" },
+            { IsoEra.CE,    TextStyle.SHORT,    Locale.US,      "AD" },
+            { IsoEra.BCE,   TextStyle.SHORT,    Locale.JAPAN,   "\u7d00\u5143\u524d" },
+            { IsoEra.CE,    TextStyle.SHORT,    Locale.JAPAN,   "\u897f\u66a6" },
+            { IsoEra.BCE,   TextStyle.NARROW,   Locale.US,      "B" },
+            { IsoEra.CE,    TextStyle.NARROW,   Locale.US,      "A" },
+            { IsoEra.BCE,   TextStyle.NARROW,   Locale.JAPAN,   "BC" },
+            { IsoEra.CE,    TextStyle.NARROW,   Locale.JAPAN,   "AD" },
+
+            // JapaneseEra
+            { JapaneseEra.MEIJI,    TextStyle.FULL,     Locale.US,      "Meiji" },
+            { JapaneseEra.TAISHO,   TextStyle.FULL,     Locale.US,      "Taisho" },
+            { JapaneseEra.SHOWA,    TextStyle.FULL,     Locale.US,      "Showa" },
+            { JapaneseEra.HEISEI,   TextStyle.FULL,     Locale.US,      "Heisei" },
+            { JapaneseEra.MEIJI,    TextStyle.FULL,     Locale.JAPAN,   "\u660e\u6cbb" },
+            { JapaneseEra.TAISHO,   TextStyle.FULL,     Locale.JAPAN,   "\u5927\u6b63" },
+            { JapaneseEra.SHOWA,    TextStyle.FULL,     Locale.JAPAN,   "\u662d\u548c" },
+            { JapaneseEra.HEISEI,   TextStyle.FULL,     Locale.JAPAN,   "\u5e73\u6210" },
+            { JapaneseEra.MEIJI,    TextStyle.SHORT,    Locale.US,      "Meiji" },
+            { JapaneseEra.TAISHO,   TextStyle.SHORT,    Locale.US,      "Taisho" },
+            { JapaneseEra.SHOWA,    TextStyle.SHORT,    Locale.US,      "Showa" },
+            { JapaneseEra.HEISEI,   TextStyle.SHORT,    Locale.US,      "Heisei" },
+            { JapaneseEra.MEIJI,    TextStyle.SHORT,    Locale.JAPAN,   "\u660e\u6cbb" },
+            { JapaneseEra.TAISHO,   TextStyle.SHORT,    Locale.JAPAN,   "\u5927\u6b63" },
+            { JapaneseEra.SHOWA,    TextStyle.SHORT,    Locale.JAPAN,   "\u662d\u548c" },
+            { JapaneseEra.HEISEI,   TextStyle.SHORT,    Locale.JAPAN,   "\u5e73\u6210" },
+            { JapaneseEra.MEIJI,    TextStyle.NARROW,   Locale.US,      "M" },
+            { JapaneseEra.TAISHO,   TextStyle.NARROW,   Locale.US,      "T" },
+            { JapaneseEra.SHOWA,    TextStyle.NARROW,   Locale.US,      "S" },
+            { JapaneseEra.HEISEI,   TextStyle.NARROW,   Locale.US,      "H" },
+            { JapaneseEra.MEIJI,    TextStyle.NARROW,   Locale.JAPAN,   "M" },
+            { JapaneseEra.TAISHO,   TextStyle.NARROW,   Locale.JAPAN,   "T" },
+            { JapaneseEra.SHOWA,    TextStyle.NARROW,   Locale.JAPAN,   "S" },
+            { JapaneseEra.HEISEI,   TextStyle.NARROW,   Locale.JAPAN,   "H" },
+
+            // ThaiBuddhistEra
+            { ThaiBuddhistEra.BEFORE_BE,    TextStyle.FULL, Locale.US,      "BC" },
+            { ThaiBuddhistEra.BE,           TextStyle.FULL, Locale.US,      "BE" },
+            { ThaiBuddhistEra.BEFORE_BE,    TextStyle.FULL, THAI,           "BC" },
+            { ThaiBuddhistEra.BE,           TextStyle.FULL, THAI,
+                "\u0e1e\u0e38\u0e17\u0e18\u0e28\u0e31\u0e01\u0e23\u0e32\u0e0a" },
+            { ThaiBuddhistEra.BEFORE_BE,    TextStyle.SHORT, Locale.US,     "BC" },
+            { ThaiBuddhistEra.BE,           TextStyle.SHORT, Locale.US,     "BE" },
+            { ThaiBuddhistEra.BEFORE_BE,    TextStyle.SHORT, THAI,
+                "\u0e1b\u0e35\u0e01\u0e48\u0e2d\u0e19\u0e04\u0e23\u0e34\u0e2a" +
+                "\u0e15\u0e4c\u0e01\u0e32\u0e25\u0e17\u0e35\u0e48" },
+            { ThaiBuddhistEra.BE,           TextStyle.SHORT, THAI,  "\u0e1e.\u0e28." },
+            { ThaiBuddhistEra.BEFORE_BE,    TextStyle.NARROW, Locale.US,    "BC" },
+            { ThaiBuddhistEra.BE,           TextStyle.NARROW, Locale.US,    "BE" },
+            { ThaiBuddhistEra.BEFORE_BE,    TextStyle.NARROW, THAI,         "BC" },
+            { ThaiBuddhistEra.BE,           TextStyle.NARROW, THAI,         "\u0e1e.\u0e28." },
+
+            // MinguoEra
+            { MinguoEra.BEFORE_ROC, TextStyle.FULL,     Locale.US,      "Before R.O.C." },
+            { MinguoEra.ROC,        TextStyle.FULL,     Locale.US,      "Minguo" },
+            { MinguoEra.BEFORE_ROC, TextStyle.FULL,     Locale.TAIWAN,  "\u6c11\u570b\u524d" },
+            { MinguoEra.ROC,        TextStyle.FULL,     Locale.TAIWAN,  "\u6c11\u570b" },
+            { MinguoEra.BEFORE_ROC, TextStyle.SHORT,    Locale.US,      "Before R.O.C." },
+            { MinguoEra.ROC,        TextStyle.SHORT,    Locale.US,      "Minguo" },
+            { MinguoEra.BEFORE_ROC, TextStyle.SHORT,    Locale.TAIWAN,  "\u6c11\u570b\u524d" },
+            { MinguoEra.ROC,        TextStyle.SHORT,    Locale.TAIWAN,  "\u6c11\u570b" },
+            { MinguoEra.BEFORE_ROC, TextStyle.NARROW,   Locale.US,      "Before R.O.C." },
+            { MinguoEra.ROC,        TextStyle.NARROW,   Locale.US,      "Minguo" },
+            { MinguoEra.BEFORE_ROC, TextStyle.NARROW,   Locale.TAIWAN,  "\u6c11\u570b\u524d" },
+            { MinguoEra.ROC,        TextStyle.NARROW,   Locale.TAIWAN,  "\u6c11\u570b" },
+
+            // HijrahEra
+            { HijrahEra.AH, TextStyle.FULL,     Locale.US,  "AH" },
+            { HijrahEra.AH, TextStyle.FULL,     EGYPT,      "\u0647\u0640" },
+            { HijrahEra.AH, TextStyle.SHORT,    Locale.US,  "AH" },
+            { HijrahEra.AH, TextStyle.SHORT,    EGYPT,      "\u0647\u0640" },
+            { HijrahEra.AH, TextStyle.NARROW,   Locale.US,  "AH" },
+            { HijrahEra.AH, TextStyle.NARROW,   EGYPT,      "\u0647\u0640" },
+        };
+    }
+
+    @Test(dataProvider="eraDisplayName")
+    public void test_eraDisplayName(Era era, TextStyle style, Locale locale, String expected) {
+        assertEquals(era.getDisplayName(style, locale), expected);
+    }
+}