1/* 2 * Copyright (c) 2002, 2007, Oracle and/or its affiliates. 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 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 */ 23package test.java.nio.Buffer; 24 25#warn This file is preprocessed before being compiled 26 27import java.nio.*; 28 29public class CopyDirect$Type$Memory 30 extends CopyDirectMemory 31{ 32 private static void init($Type$Buffer b) { 33 int n = b.capacity(); 34 b.clear(); 35 for (int i = 0; i < n; i++) 36 b.put(i, ($type$)ic(i)); 37 b.limit(n); 38 b.position(0); 39 } 40 41 private static void init($type$ [] a) { 42 for (int i = 0; i < a.length; i++) 43 a[i] = ($type$)ic(i + 1); 44 } 45 46 public static void test() { 47#if[byte] 48 ByteBuffer b = ByteBuffer.allocateDirect(1024 * 1024 + 1024); 49#else[byte] 50 ByteBuffer bb = ByteBuffer.allocateDirect(1024 * 1024 + 1024); 51 $Type$Buffer b = bb.as$Type$Buffer(); 52#end[byte] 53 init(b); 54 $type$ [] a = new $type$[b.capacity()]; 55 init(a); 56 57 // copyFrom$Type$Array (a -> b) 58 b.put(a); 59 for (int i = 0; i < a.length; i++) 60 ck(b, b.get(i), ($type$)ic(i + 1)); 61 62 // copyTo$Type$Array (b -> a) 63 init(b); 64 init(a); 65 b.get(a); 66 for (int i = 0; i < a.length; i++) 67 if (a[i] != b.get(i)) 68 fail("Copy failed at " + i + ": '" 69 + a[i] + "' != '" + b.get(i) + "'"); 70 } 71} 72