blobimpl.java

来自「用Java实现的23个常用设计模式源代码」· Java 代码 · 共 105 行

JAVA
105
字号
//$Id: BlobImpl.java,v 1.4.2.2 2003/11/27 16:09:59 oneovthafew Exp $package net.sf.hibernate.lob;import java.io.ByteArrayInputStream;import java.io.InputStream;import java.io.OutputStream;import java.sql.Blob;import java.sql.SQLException;/** * A dummy implementation of <tt>java.sql.Blob</tt> that * may be used to insert new data into a BLOB. * @author Gavin King */public class BlobImpl implements Blob {		private InputStream stream;	private int length;	public BlobImpl(byte[] bytes) {		this.stream = new ByteArrayInputStream(bytes);		this.length = bytes.length;	}		public BlobImpl(InputStream stream, int length) {		this.stream = stream;		this.length = length;	}		/**	 * @see java.sql.Blob#length()	 */	public long length() throws SQLException {		return length;	}		/**	 * @see java.sql.Blob#truncate(long)	 */	public void truncate(long arg0) throws SQLException {		excep();	}		/**	 * @see java.sql.Blob#getBytes(long, int)	 */	public byte[] getBytes(long arg0, int arg1) throws SQLException {		excep(); return null;	}		/**	 * @see java.sql.Blob#setBytes(long, byte[])	 */	public int setBytes(long arg0, byte[] arg1) throws SQLException {		excep(); return 0;	}		/**	 * @see java.sql.Blob#setBytes(long, byte[], int, int)	 */	public int setBytes(long arg0, byte[] arg1, int arg2, int arg3)	throws SQLException {		excep(); return 0;	}		/**	 * @see java.sql.Blob#position(byte[], long)	 */	public long position(byte[] arg0, long arg1) throws SQLException {		excep(); return 0;	}		/**	 * @see java.sql.Blob#getBinaryStream()	 */	public InputStream getBinaryStream() throws SQLException {		return stream;	}		/**	 * @see java.sql.Blob#setBinaryStream(long)	 */	public OutputStream setBinaryStream(long arg0) throws SQLException {		excep(); return null;	}		/**	 * @see java.sql.Blob#position(Blob, long)	 */	public long position(Blob arg0, long arg1) throws SQLException {		excep(); return 0;	}		private static void excep() {		throw new UnsupportedOperationException("Blob may not be manipulated from creating session");	}	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?