import java.io.OutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.novell.java.io.DataAccessable;
import com.novell.service.file.nw.DataAccessableParameters;
import com.novell.service.file.nw.NFileOutputStream;
import com.novell.service.file.nw.NFileInputStream;
import com.novell.utility.naming.Environment;
class ExtendedAttribute
{
public static void main(String args[])
{
if (args.length < 2)
{
help();
}
String url = args[0];
String ea = args[1];
StaticAttributeValueInterface sai = new TextualStatic(true);
Hashtable systemProps = new Hashtable();
systemProps.put(
Context.INITIAL_CONTEXT_FACTORY,
Environment.FS_INITIAL_CONTEXT_FACTORY);
systemProps.put(Context.PROVIDER_URL, url);
boolean osOpen = false;
boolean isOpen = false;
OutputStream os = null;
InputStream is = null;
try
{
Object obj = new InitialContext(systemProps).lookup("");
System.out.println("\nCreating EA " + ea + " in " + url + "\n");
if (obj instanceof DataAccessable)
{
os = new NFileOutputStream(
ea,
(DataAccessable)obj,
DataAccessableParameters.READ_WRITE,
DataAccessableParameters.EA_STREAM_SELECTOR);
osOpen = true;
sai.writeStream(os);
os.close();
osOpen = false;
is = new NFileInputStream(
ea,
(DataAccessable)obj,
DataAccessableParameters.READ,
DataAccessableParameters.EA_STREAM_SELECTOR);
isOpen = true;
sai.readStream(is);
is.close();
isOpen = false;
}
else
{
System.out.println("error: " + url + " is not DataAccessable");
System.exit(-1);
}
}
catch (IOException ioe)
{
try
{
if (osOpen)
os.close();
if (isOpen)
is.close();
}
catch (IOException nested)
{
System.out.println("error with close in catch: " + nested);
nested.printStackTrace();
}
System.out.println("error with stream: " + ioe);
ioe.printStackTrace();
System.exit(-1);
}
catch(javax.naming.NamingException e)
{
System.out.println("\nException thrown: " + e);
e.printStackTrace();
System.exit(-1);
}
System.exit(0);
}
private static void help()
{
System.out.println(
"\nTo use this example program enter the following:\n");
System.out.println(
"\tjava ExtendedAtribute <url> <ea>\n");
System.out.println(
"\t\turl = name of the directory or file to create the new EA in");
System.out.println("\t\t my_server/my_volume/my_dir");
System.out.println(
"\t\tea = new Extended Attribute name to create");
System.out.println("");
System.exit(-1);
}
}