J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2000 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * @test |
| 26 | * @bug 4159554 |
| 27 | * @summary Problem with UUDecoder |
| 28 | * |
| 29 | */ |
| 30 | |
| 31 | import sun.misc.*; |
| 32 | import java.io.*; |
| 33 | |
| 34 | public class DecodeBuffer { |
| 35 | |
| 36 | public static void main(String[] args) throws Exception { |
| 37 | String encoded; |
| 38 | // text to encode and decode |
| 39 | String originalText = "Hi There, please encode and decode me"; |
| 40 | UUDecoder uuD = new UUDecoder(); |
| 41 | |
| 42 | encoded = "begin 644 encoder.buf\r\n" + |
| 43 | "E2&D@5&AE<F4L('!L96%S92!E;F-O9&4@86YD(&1E8V]D92!M90$!\r\n"+ |
| 44 | " \r\nend\r\n"; |
| 45 | check (uuD, encoded, originalText); |
| 46 | |
| 47 | encoded = "begin 644 encoder.buf\n" + |
| 48 | "E2&D@5&AE<F4L('!L96%S92!E;F-O9&4@86YD(&1E8V]D92!M90$!\n"+ |
| 49 | " \nend\n"; |
| 50 | check (uuD, encoded, originalText); |
| 51 | |
| 52 | encoded = "begin 644 encoder.buf\r" + |
| 53 | "E2&D@5&AE<F4L('!L96%S92!E;F-O9&4@86YD(&1E8V]D92!M90$!\r"+ |
| 54 | " \rend\r"; |
| 55 | check (uuD, encoded, originalText); |
| 56 | |
| 57 | // Multi-line Unix text file |
| 58 | |
| 59 | String s1 = "begin 644 f\n"+ |
| 60 | "M3W)I9VYL(\"I(:2!4:&5R92P@<&QE87-E(&5N8V]D92!A;F0@9&5C;V1E(&UE\n"+ |
| 61 | "M*@IA;F0@;64@06YD($UE(&%N1\"!M92!!;F0@344@04Y$($U%(%I80U8@,3(S\n"+ |
| 62 | "-97)T\"E5)3U @45=%\"DUE\n"+ |
| 63 | " \nend\n"; |
| 64 | |
| 65 | String s2 = "Orignl *Hi There, please encode and decode me*\n"+ |
| 66 | "and me And Me anD me And ME AND ME ZXCV 123ert\n"+ |
| 67 | "UIOP QWE\n"; |
| 68 | check (uuD, s1, s2); |
| 69 | |
| 70 | // Multi-line Windows text file |
| 71 | |
| 72 | s1 = "begin 644 f\n"+ |
| 73 | "M2&5L;&\\@22!A;2!A(&UU;'1I;&EN92!F:6QE#0IC<F5A=&5D(&]N(%=I;F1O\r\n"+ |
| 74 | "M=W,L('1O('1E<W0@=&AE(%5516YC;V1E<@T*86YD(%551&5C;V1E<B!C;&%S\r\n"+ |
| 75 | "$<V5S+G1O\r\n"+ " \r\nend\r\n"; |
| 76 | s2="Hello I am a multiline file\r\n"+ |
| 77 | "created on Windows, to test the UUEncoder\r\n"+ |
| 78 | "and UUDecoder classes."; |
| 79 | check (uuD, s1, s2); |
| 80 | } |
| 81 | |
| 82 | public static void check (UUDecoder uuD, String s, String original) throws Exception { |
| 83 | String decoded; |
| 84 | // do UU stuff |
| 85 | decoded = new String(uuD.decodeBuffer(s)); |
| 86 | if (!decoded.equals (original)) { |
| 87 | throw new Exception ("decoded text not same as original"); |
| 88 | } |
| 89 | } |
| 90 | } |