< prev index next >

test/java/io/Serializable/corruptedUTFConsumption/CorruptedUTFConsumption.java

Print this page




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 4450867
  26  * @summary Although technically the behavior of ObjectInputStream following a
  27  *          UTFDataFormatException is unspecified, verify that
  28  *          ObjectInputStream consumes at most the expected number of utf
  29  *          bytes, even if the last byte(s) of the utf string indicate that the
  30  *          string overflows its expected length.

  31  */
  32 
  33 import java.io.*;
  34 import java.util.Random;
  35 
  36 public class CorruptedUTFConsumption {
  37 
  38     static Random rand = new Random(System.currentTimeMillis());
  39 
  40     public static void main(String[] args) throws Exception {
  41         StringBuffer sbuf = new StringBuffer();
  42         ByteArrayOutputStream bout = new ByteArrayOutputStream();
  43         DataOutputStream dout = new DataOutputStream(bout);
  44 
  45         for (int i = 0; i < 1200; i++) {
  46             sbuf.append(i % 10);
  47             bout.reset();
  48             dout.writeUTF(sbuf.toString());
  49             byte[] utf = bout.toByteArray();
  50 




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 4450867
  26  * @summary Although technically the behavior of ObjectInputStream following a
  27  *          UTFDataFormatException is unspecified, verify that
  28  *          ObjectInputStream consumes at most the expected number of utf
  29  *          bytes, even if the last byte(s) of the utf string indicate that the
  30  *          string overflows its expected length.
  31  * @key randomness
  32  */
  33 
  34 import java.io.*;
  35 import java.util.Random;
  36 
  37 public class CorruptedUTFConsumption {
  38 
  39     static Random rand = new Random(System.currentTimeMillis());
  40 
  41     public static void main(String[] args) throws Exception {
  42         StringBuffer sbuf = new StringBuffer();
  43         ByteArrayOutputStream bout = new ByteArrayOutputStream();
  44         DataOutputStream dout = new DataOutputStream(bout);
  45 
  46         for (int i = 0; i < 1200; i++) {
  47             sbuf.append(i % 10);
  48             bout.reset();
  49             dout.writeUTF(sbuf.toString());
  50             byte[] utf = bout.toByteArray();
  51 


< prev index next >