1 /********************************************************************** 2 * IncompleteIOException.java 3 * created on 07.03.2005 by netseeker 4 * $Source: /cvsroot/ejoe/EJOE/src/de/netseeker/ejoe/io/IncompleteIOException.java,v $ 5 * $Date: 2006/11/05 16:31:15 $ 6 * $Revision: 1.12 $ 7 * 8 * ==================================================================== 9 * 10 * Copyright 2006 netseeker aka Michael Manske 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * ==================================================================== 24 * 25 * This file is part of the ejoe framework. 26 * For more information on the author, please see 27 * <http://www.manskes.de/>. 28 * 29 *********************************************************************/ 30 package de.netseeker.ejoe.io; 31 32 import java.io.IOException; 33 import java.nio.ByteBuffer; 34 35 /*** 36 * A special exception type which will be thrown when a incomplete non-blocking IO read or write operation occurs. 37 * 38 * @author netseeker 39 * @since 0.3.3 40 */ 41 public class IncompleteIOException extends IOException 42 { 43 private static final long serialVersionUID = 1L; 44 45 private transient ByteBuffer _buf; 46 47 private int _selectionInterest; 48 49 /*** 50 * Creates a new IncompleteIOException and stores the given ByteBuffer for possible reuse 51 * 52 * @param buf the ByteBuffer containing the partial read/not yet written data 53 */ 54 public IncompleteIOException(ByteBuffer buf) 55 { 56 this._buf = buf; 57 } 58 59 /*** 60 * Creates a new IncompleteIOException and stores the given ByteBuffer for possible reuse. Additionally it stores 61 * the type of the operation which has thrown this Exception. 62 * 63 * @param buf the ByteBuffer containing the partial read/not yet written data 64 * @param selectionInterest type of the io operation which has caused the exception, can be either 65 * SelectionKey.OP_READ or SelectionKey.OP_WRITE 66 * @see java.nio.channels.SelectionKey 67 */ 68 public IncompleteIOException(ByteBuffer buf, int selectionInterest) 69 { 70 setIOBuffer( buf ); 71 this._selectionInterest = selectionInterest; 72 } 73 74 /*** 75 * Returns the contained ByteBuffer. 76 * 77 * @return the internal ByteBuffer containing partial data, may be null 78 */ 79 public ByteBuffer getIOBuffer() 80 { 81 return this._buf; 82 } 83 84 /*** 85 * Sets the internal ByteBuffer containing partial data, can be also null 86 * 87 * @param buf The ByteBuffer to set. 88 */ 89 public void setIOBuffer( ByteBuffer buf ) 90 { 91 if ( buf == null && this._buf != null ) 92 { 93 this._buf.clear(); 94 } 95 this._buf = buf; 96 } 97 98 /*** 99 * Returns the type of this incomplete io exception, either incomplete write or incomplete read. 100 * 101 * @return SelectionKey.OP_WRITE for incomplete write, SelectionKey.OP_READ for incomplete write 102 */ 103 public int getSelectionInterest() 104 { 105 return this._selectionInterest; 106 } 107 108 /*** 109 * Sets the type of this incomplete io exception, either incomplete write or incomplete read. 110 * 111 * @param interest SelectionKey.OP_WRITE for incomplete write, SelectionKey.OP_READ for incomplete write 112 */ 113 public void setSelectionInterest( int interest ) 114 { 115 this._selectionInterest = interest; 116 } 117 }