3445N/A/*
3445N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3445N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3445N/A *
3445N/A * This code is free software; you can redistribute it and/or modify it
3445N/A * under the terms of the GNU General Public License version 2 only, as
3445N/A * published by the Free Software Foundation.
3445N/A *
3445N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3445N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3445N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3445N/A * version 2 for more details (a copy is included in the LICENSE file that
3445N/A * accompanied this code).
3445N/A *
3445N/A * You should have received a copy of the GNU General Public License version
3445N/A * 2 along with this work; if not, write to the Free Software Foundation,
3445N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3445N/A *
3445N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3445N/A * or visit www.oracle.com if you need additional information or have any
3445N/A * questions.
3445N/A *
3445N/A */
3445N/A
3445N/A/**
3445N/A * @test
3445N/A * @bug 6732154
3445N/A * @summary REG: Printing an Image using image/gif doc flavor crashes the VM, Solsparc
3445N/A *
3445N/A * @run main/othervm -Xcomp -XX:CompileOnly="Test6732154::ascii85Encode" Test6732154
3445N/A */
3445N/Apublic class Test6732154 {
3445N/A
3445N/A // Exact copy of sun.print.PSPrinterJob.ascii85Encode([b)[b
3445N/A private byte[] ascii85Encode(byte[] inArr) {
3445N/A byte[] outArr = new byte[((inArr.length+4) * 5 / 4) + 2];
3445N/A long p1 = 85;
3445N/A long p2 = p1*p1;
3445N/A long p3 = p1*p2;
3445N/A long p4 = p1*p3;
3445N/A byte pling = '!';
3445N/A
3445N/A int i = 0;
3445N/A int olen = 0;
3445N/A long val, rem;
3445N/A
3445N/A while (i+3 < inArr.length) {
3445N/A val = ((long)((inArr[i++]&0xff))<<24) +
3445N/A ((long)((inArr[i++]&0xff))<<16) +
3445N/A ((long)((inArr[i++]&0xff))<< 8) +
3445N/A ((long)(inArr[i++]&0xff));
3445N/A if (val == 0) {
3445N/A outArr[olen++] = 'z';
3445N/A } else {
3445N/A rem = val;
3445N/A outArr[olen++] = (byte)(rem / p4 + pling); rem = rem % p4;
3445N/A outArr[olen++] = (byte)(rem / p3 + pling); rem = rem % p3;
3445N/A outArr[olen++] = (byte)(rem / p2 + pling); rem = rem % p2;
3445N/A outArr[olen++] = (byte)(rem / p1 + pling); rem = rem % p1;
3445N/A outArr[olen++] = (byte)(rem + pling);
3445N/A }
3445N/A }
3445N/A // input not a multiple of 4 bytes, write partial output.
3445N/A if (i < inArr.length) {
3445N/A int n = inArr.length - i; // n bytes remain to be written
3445N/A
3445N/A val = 0;
3445N/A while (i < inArr.length) {
3445N/A val = (val << 8) + (inArr[i++]&0xff);
3445N/A }
3445N/A
3445N/A int append = 4 - n;
3445N/A while (append-- > 0) {
3445N/A val = val << 8;
3445N/A }
3445N/A byte []c = new byte[5];
3445N/A rem = val;
3445N/A c[0] = (byte)(rem / p4 + pling); rem = rem % p4;
3445N/A c[1] = (byte)(rem / p3 + pling); rem = rem % p3;
3445N/A c[2] = (byte)(rem / p2 + pling); rem = rem % p2;
3445N/A c[3] = (byte)(rem / p1 + pling); rem = rem % p1;
3445N/A c[4] = (byte)(rem + pling);
3445N/A
3445N/A for (int b = 0; b < n+1 ; b++) {
3445N/A outArr[olen++] = c[b];
3445N/A }
3445N/A }
3445N/A
3445N/A // write EOD marker.
3445N/A outArr[olen++]='~'; outArr[olen++]='>';
3445N/A
3445N/A /* The original intention was to insert a newline after every 78 bytes.
3445N/A * This was mainly intended for legibility but I decided against this
3445N/A * partially because of the (small) amount of extra space, and
3445N/A * partially because for line breaks either would have to hardwire
3445N/A * ascii 10 (newline) or calculate space in bytes to allocate for
3445N/A * the platform's newline byte sequence. Also need to be careful
3445N/A * about where its inserted:
3445N/A * Ascii 85 decoder ignores white space except for one special case:
3445N/A * you must ensure you do not split the EOD marker across lines.
3445N/A */
3445N/A byte[] retArr = new byte[olen];
3445N/A System.arraycopy(outArr, 0, retArr, 0, olen);
3445N/A return retArr;
3445N/A }
3445N/A
3445N/A public static void main(String[] args) {
3445N/A new Test6732154().ascii85Encode(new byte[0]);
3445N/A System.out.println("Test passed.");
3445N/A }
3445N/A}