Source code: com/flexstor/common/util/FileClassLoader.java
1 /*
2 * FileClassLoader.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:31 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.common.util;
12
13 import java.io.FileInputStream;
14 import java.io.IOException;
15
16 /**
17 * Loads class bytes from a file.
18 */
19 public class FileClassLoader
20 extends FlexClassLoader
21 {
22 private String sFilePrefix;
23
24 /**
25 * Attempts to
26 * load from a local file using the relative "filePrefix",
27 * ie starting at the current directory. For example
28 * @param filePrefix could be "webSiteClasses\\site1\\".
29 */
30 public FileClassLoader(String sFilePrefix)
31 {
32 this.sFilePrefix = sFilePrefix;
33 }
34
35 protected byte[] loadClassBytes(String sClassName)
36 throws IOException
37 {
38 byte result[];
39
40 setClassNameReplacementChar(java.io.File.separatorChar);
41 sClassName = formatClassName(sClassName);
42 String fileName = (sFilePrefix == null ? sClassName : sFilePrefix + sClassName);
43
44 Diagnostic.trace(Diagnostic.CAT_CLASSLDR, "Attempt from file: " + fileName);
45 FileInputStream inStream = new FileInputStream(fileName);
46 // *** Is available() reliable for large files?
47 result = new byte[inStream.available()];
48 inStream.read(result);
49 inStream.close();
50
51 return result;
52 }
53
54 } // end of class