/* * Created on Jul 10, 2004 * Created by Heinz Doerr * Copyright (c) 2000/01/02/03/04 by ChaNet, Heinz Doerr */ package com.mysql.jdbc; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; import java.lang.reflect.Method; import java.sql.Connection; /** * @author Heinz Doerr * */ public interface ILocalFileInputStream { public void open(String path) throws IOException; public int read(byte[] buf) throws IOException; public int read(byte[] buf, int off, int len) throws IOException; public void close() throws IOException; public class Connection { static public final boolean hasCapability(java.sql.Connection conn) { try { return conn.getClass().getMethod("setLocalFileInputStream", new Class[] { ILocalFileInputStream.class }) != null; } catch (Exception e) { } return false; } static public final void setLocalFileInputStream(java.sql.Connection conn, ILocalFileInputStream locFileStream) throws NoSuchMethodException { try { Method mtd= conn.getClass().getMethod("setLocalFileInputStream", new Class[] { ILocalFileInputStream.class }); if (mtd != null) { mtd.invoke(conn, new Object[] { locFileStream } ); return; } } catch (Exception e) { } throw new NoSuchMethodException("Your db connection does not allow to setLocalFileInputStream(...)!"); } } public class DefaultImpl implements ILocalFileInputStream { BufferedInputStream bis; public void open(String path) throws IOException { if (bis != null) bis.close(); // just to be shure bis= new BufferedInputStream(new FileInputStream(path)); } public final int read(byte[] buf) throws IOException { return bis.read(buf, 0, buf.length); } public int read(byte[] buf, int off, int len) throws IOException { return bis.read(buf, off, len); } public void close() throws IOException { if (bis != null) { try { bis.close(); } finally { bis= null; } } } } }