< prev index next >

test/jdk/java/nio/Buffer/BasicByte.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 28,39 **** --- 28,48 ---- * independently of the rest of the source tree. */ // -- This file was mechanically generated: Do not edit! -- // + + import java.io.IOException; + import java.io.UncheckedIOException; + import java.nio.*; + import java.nio.channels.FileChannel; + import java.nio.file.Files; + import java.nio.file.Path; + + public class BasicByte extends Basic {
*** 467,476 **** --- 476,520 ---- if (as.limit() != ec) { fail("Buffer capacity incorrect, expected: " + ec, as); } } } + + // mapped buffers + try { + for (MappedByteBuffer bb : mappedBuffers()) { + try { + int offset = bb.alignmentOffset(1, 4); + ck(bb, offset >= 0); + } catch (UnsupportedOperationException e) { + System.out.println("Not applicable, UOE thrown: "); + } + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + private static MappedByteBuffer[] mappedBuffers() throws IOException { + return new MappedByteBuffer[]{ + createMappedBuffer(new byte[]{0, 1, 2, 3}), + createMappedBuffer(new byte[]{0, 1, 2, -3, + 45, 6, 7, 78, 3, -7, 6, 7, -128, 127}), + }; + } + + private static MappedByteBuffer createMappedBuffer(byte[] contents) + throws IOException { + Path tempFile = Files.createTempFile("mbb", null); + tempFile.toFile().deleteOnExit(); + Files.write(tempFile, contents); + try (FileChannel fc = FileChannel.open(tempFile)) { + MappedByteBuffer map = + fc.map(FileChannel.MapMode.READ_ONLY, 0, contents.length); + map.load(); + return map; + } } private static void fail(String problem, ByteBuffer xb, ByteBuffer yb,
< prev index next >