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.FileLock;
025: import java.nio.channels.NonReadableChannelException;
026: import java.nio.channels.WritableByteChannel;
027:
028: public final class WriteOnlyFileChannel extends FileChannelImpl {
029:
030: private boolean append = false;
031:
032: public WriteOnlyFileChannel(Object stream, long handle) {
033: super (stream, handle);
034: }
035:
036: public WriteOnlyFileChannel(Object stream, long handle,
037: boolean isAppend) {
038: super (stream, handle);
039: append = isAppend;
040: }
041:
042: /*
043: * (non-Javadoc)
044: *
045: * @see org.apache.harmony.nio.internal.FileChannelImpl#position()
046: */
047: public long position() throws IOException {
048: return append ? size() : super .position();
049: }
050:
051: public long transferTo(long position, long count,
052: WritableByteChannel target) throws IOException {
053: openCheck();
054: if (!target.isOpen()) {
055: throw new ClosedChannelException();
056: }
057: throw new NonReadableChannelException();
058: }
059:
060: public long read(ByteBuffer[] buffers, int offset, int length)
061: throws IOException {
062: if (offset < 0 || length < 0
063: || offset + length > buffers.length) {
064: throw new IndexOutOfBoundsException();
065: }
066: openCheck();
067: throw new NonReadableChannelException();
068: }
069:
070: public int read(ByteBuffer buffer) throws IOException {
071: openCheck();
072: throw new NonReadableChannelException();
073: }
074:
075: public int read(ByteBuffer buffer, long position)
076: throws IOException {
077: if (null == buffer) {
078: throw new NullPointerException();
079: }
080: if (position < 0) {
081: throw new IllegalArgumentException();
082: }
083: throw new NonReadableChannelException();
084: }
085:
086: public MappedByteBuffer map(MapMode mode, long position, long size)
087: throws IOException {
088: openCheck();
089: if (mode == null) {
090: throw new NullPointerException();
091: }
092: if (position < 0 || size < 0 || size > Integer.MAX_VALUE) {
093: throw new IllegalArgumentException();
094: }
095: throw new NonReadableChannelException();
096: }
097:
098: public int write(ByteBuffer buffer) throws IOException {
099: if (append) {
100: position(size());
101: }
102: return super .write(buffer);
103: }
104:
105: protected final FileLock basicLock(long position, long size,
106: boolean shared, boolean wait) throws IOException {
107: if (shared) {
108: throw new NonReadableChannelException();
109: }
110: return super.basicLock(position, size, shared, wait);
111: }
112: }
|