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/webnfs/WebNfsBufferedOutputStream.java


1   /*
2    * WebNfsBufferedOutputStream.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.BufferedOutputStream;
14  
15  import com.flexstor.common.io.xfile.parsers.XStringValidator;
16  import com.sun.xfile.XFileOutputStream;
17  
18  /**
19  * This subclass of XFileOutputStream 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 WebNfsBufferedOutputStream
31     extends BufferedOutputStream
32  {
33     public WebNfsBufferedOutputStream(WebNfsFile xFile)
34        throws java.io.IOException
35     {
36        super( new XFileOutputStream(checkForAccess(xFile)) );
37     }
38  
39     public WebNfsBufferedOutputStream(String str)
40        throws java.io.IOException
41     {
42        this( new WebNfsFile(str) );
43     }
44  
45      public WebNfsBufferedOutputStream(WebNfsFile xFile, int bufferSize)
46          throws java.io.IOException
47      {
48          super(new XFileOutputStream(checkForAccess(xFile)),bufferSize);
49      }
50  
51     public WebNfsBufferedOutputStream(WebNfsFile xFile, boolean append)
52        throws java.io.IOException
53     {
54        super( new XFileOutputStream(checkForAccess(xFile), append) );
55     }
56  
57     public WebNfsBufferedOutputStream(String str, boolean append)
58        throws java.io.IOException
59     {
60        this( new WebNfsFile(str), append );
61     }
62  
63     public static String checkForAccess( WebNfsFile file )
64     {
65        // If the OS is not Solaris, then treat is as a local path
66        String str = file.isOSSolaris() ? file.getAbsolutePath() : file.getLocalPath();
67  
68        try
69        {
70           (new XFileOutputStream( str )).close();
71           return str;
72        }
73        catch( java.io.IOException ioe )
74        {
75           WebNfsFile xFile = new WebNfsFile( str );
76           if ( xFile.isLocalPath() )
77              return XStringValidator.encodeURLString( xFile.getLocalPath() );
78           else
79              return str;
80        }
81     }
82  }