jdk/test/sun/misc/Encode/DecodeBuffer.java
author ihse
Mon, 09 Mar 2015 10:39:16 +0100
changeset 29304 81a723f8d33c
parent 5506 202f599c92aa
child 30820 0d4717a011d3
permissions -rw-r--r--
8074096: Disable (most) native warnings in JDK on a per-library basis Reviewed-by: erikj, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4159554
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Problem with UUDecoder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.misc.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
public class DecodeBuffer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        String encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        // text to encode and decode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        String originalText = "Hi There, please encode and decode me";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        UUDecoder uuD = new UUDecoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        encoded = "begin 644 encoder.buf\r\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
          "E2&D@5&AE<F4L('!L96%S92!E;F-O9&4@86YD(&1E8V]D92!M90$!\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
          " \r\nend\r\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        check (uuD, encoded, originalText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        encoded = "begin 644 encoder.buf\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
          "E2&D@5&AE<F4L('!L96%S92!E;F-O9&4@86YD(&1E8V]D92!M90$!\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
          " \nend\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        check (uuD, encoded, originalText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        encoded = "begin 644 encoder.buf\r" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
          "E2&D@5&AE<F4L('!L96%S92!E;F-O9&4@86YD(&1E8V]D92!M90$!\r"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
          " \rend\r";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        check (uuD, encoded, originalText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        // Multi-line Unix text file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        String s1 = "begin 644 f\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        "M3W)I9VYL(\"I(:2!4:&5R92P@<&QE87-E(&5N8V]D92!A;F0@9&5C;V1E(&UE\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        "M*@IA;F0@;64@06YD($UE(&%N1\"!M92!!;F0@344@04Y$($U%(%I80U8@,3(S\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        "-97)T\"E5)3U @45=%\"DUE\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        " \nend\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        String s2 = "Orignl *Hi There, please encode and decode me*\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        "and me And Me anD me And ME AND ME ZXCV 123ert\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        "UIOP QWE\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        check (uuD, s1, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        // Multi-line Windows text file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        s1 = "begin 644 f\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        "M2&5L;&\\@22!A;2!A(&UU;'1I;&EN92!F:6QE#0IC<F5A=&5D(&]N(%=I;F1O\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        "M=W,L('1O('1E<W0@=&AE(%5516YC;V1E<@T*86YD(%551&5C;V1E<B!C;&%S\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        "$<V5S+G1O\r\n"+ " \r\nend\r\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        s2="Hello I am a multiline file\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        "created on Windows, to test the UUEncoder\r\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        "and UUDecoder classes.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        check (uuD, s1, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static void check (UUDecoder uuD, String s, String original) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        String decoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        // do UU stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        decoded = new String(uuD.decodeBuffer(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (!decoded.equals (original)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            throw new Exception ("decoded text not same as original");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
}