Source code: com/flexstor/common/io/xfile/webnfs/WebNfsBufferedInputStream.java
1 /*
2 * WebNfsBufferedInputStream.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.io.xfile.webnfs;
12
13 import java.io.BufferedInputStream;
14
15 import com.flexstor.common.io.xfile.parsers.XStringValidator;
16 import com.sun.xfile.XFileInputStream;
17
18 /**
19 * This subclass of XFileInputStream overwrites the constructors which otherwise will fail if:
20 *
21 * - The protocol used is a NFS URL and the path specified is mounted from another server
22 * OR
23 * - The path contains some escape codes and special characters that must be preserved.
24 *
25 * Inside the constructors we first determine if the path is local to the JVM server; if so,
26 * then we replace special characters in the path with its respective escape code.
27 *
28 * David C. 03/02/00
29 */
30 public class WebNfsBufferedInputStream
31 extends BufferedInputStream
32 {
33 public WebNfsBufferedInputStream(WebNfsFile xFile)
34 throws java.io.IOException
35 {
36 super( new XFileInputStream(checkForAccess(xFile)) );
37 }
38
39 public WebNfsBufferedInputStream(String str)
40 throws java.io.IOException
41 {
42 this( new WebNfsFile(str) );
43 }
44
45 public WebNfsBufferedInputStream(WebNfsFile file, int bufferSize)
46 throws java.io.IOException
47 {
48 super(new XFileInputStream(checkForAccess(file)), bufferSize);
49 }
50
51 public static String checkForAccess( WebNfsFile file )
52 {
53 // If the OS is not Solaris, then treat is as a local path
54 String str = file.isOSSolaris() ? file.getAbsolutePath() : file.getLocalPath();
55
56 try
57 {
58 (new XFileInputStream( str )).close();
59 return str;
60 }
61 catch( java.io.IOException ioe )
62 {
63 WebNfsFile xFile = new WebNfsFile( str );
64 if ( xFile.isLocalPath() )
65 return XStringValidator.encodeURLString( xFile.getLocalPath() );
66 else
67 return str;
68 }
69 }
70 }