001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.nio.internal;
019:
020: import java.io.IOException;
021: import java.nio.ByteBuffer;
022: import java.nio.MappedByteBuffer;
023: import java.nio.channels.ClosedChannelException;
024: import java.nio.channels.FileChannel;
025: import java.nio.channels.FileLock;
026: import java.nio.channels.NonWritableChannelException;
027: import java.nio.channels.ReadableByteChannel;
028:
029: import org.apache.harmony.luni.platform.IMemorySystem;
030:
031: public final class ReadOnlyFileChannel extends FileChannelImpl {
032: public ReadOnlyFileChannel(Object stream, long handle) {
033: super (stream, handle);
034: }
035:
036: public final int write(ByteBuffer buffer, long position)
037: throws IOException {
038: if (null == buffer) {
039: throw new NullPointerException();
040: }
041: if (position < 0) {
042: throw new IllegalArgumentException();
043: }
044: throw new NonWritableChannelException();
045: }
046:
047: public final int write(ByteBuffer buffer) throws IOException {
048: openCheck();
049: throw new NonWritableChannelException();
050: }
051:
052: public final long write(ByteBuffer[] buffers, int offset, int length)
053: throws IOException {
054: if (offset < 0 || length < 0
055: || (offset + length) > buffers.length) {
056: throw new IndexOutOfBoundsException();
057: }
058: openCheck();
059: throw new NonWritableChannelException();
060: }
061:
062: public final FileChannel truncate(long size) throws IOException {
063: openCheck();
064: if (size < 0) {
065: throw new IllegalArgumentException();
066: }
067: throw new NonWritableChannelException();
068: }
069:
070: public final long transferFrom(ReadableByteChannel src,
071: long position, long count) throws IOException {
072: openCheck();
073: if (!src.isOpen()) {
074: throw new ClosedChannelException();
075: }
076: throw new NonWritableChannelException();
077: }
078:
079: public final MappedByteBuffer map(MapMode mode, long position,
080: long size) throws IOException {
081: openCheck();
082: if (mode == null) {
083: throw new NullPointerException();
084: }
085: if (position < 0 || size < 0 || size > Integer.MAX_VALUE) {
086: throw new IllegalArgumentException();
087: }
088: if (mode != MapMode.READ_ONLY) {
089: throw new NonWritableChannelException();
090: }
091: return super .mapImpl(IMemorySystem.MMAP_READ_ONLY, position,
092: size);
093: }
094:
095: public final void force(boolean metadata) throws IOException {
096: openCheck();
097: return;
098: }
099:
100: protected final FileLock basicLock(long position, long size,
101: boolean shared, boolean wait) throws IOException {
102: if (!shared) {
103: throw new NonWritableChannelException();
104: }
105: return super .basicLock(position, size, shared, true);
106: }
107: }
|