Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/io/xfile/FlexXRandomAccessFile.java


1   /*
2    * FlexXRandomAccessFile.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:39 $ 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;
12  
13  import com.flexstor.common.io.xfile.parsers.XStringValidator;
14  import com.sun.xfile.XRandomAccessFile;
15  
16  /**
17  * This subclass of XRandomAccessFile overwrites the constructors which otherwise will fail if:
18  * 
19  *     - The protocol used is a NFS URL and the path specified is mounted from another server
20  *     OR
21  *     - The path contains some escape codes and special characters that must be preserved.
22  * 
23  * Inside the constructors we first determine if the path is local to the JVM server; if so,
24  * then we replace special characters in the path with its respective escape code.
25  *
26  * David C. 03/02/00
27  */
28  public class FlexXRandomAccessFile
29     extends XRandomAccessFile
30  {
31     public FlexXRandomAccessFile(FlexXFile xFile, String mode)
32        throws java.io.IOException
33     {
34        this( xFile.getAbsolutePath(), mode );
35     }
36  
37     public FlexXRandomAccessFile(String str, String mode)
38        throws java.io.IOException
39     {
40        super( checkForAccess(str, mode), mode );
41     }
42     
43     public static String checkForAccess( String str, String mode )
44     {
45        try
46        {
47           (new XRandomAccessFile( str, mode )).close();
48           return str;
49        }
50        catch( java.io.IOException ioe )
51        {
52           FlexXFile xFile = new FlexXFile( str );
53           if ( xFile.isLocalPath() )
54              return XStringValidator.encodeURLString( xFile.getLocalPath() );
55           else
56              return str;
57        }
58     }
59  }