|
From: <ha...@us...> - 2007-08-23 18:56:24
|
Revision: 1711
http://cogkit.svn.sourceforge.net/cogkit/?rev=1711&view=rev
Author: hategan
Date: 2007-08-23 11:56:23 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
and its first bug fixes
Modified Paths:
--------------
trunk/current/src/cog/modules/provider-dcache/src/org/globus/cog/abstraction/impl/file/dcache/FileResourceImpl.java
Modified: trunk/current/src/cog/modules/provider-dcache/src/org/globus/cog/abstraction/impl/file/dcache/FileResourceImpl.java
===================================================================
--- trunk/current/src/cog/modules/provider-dcache/src/org/globus/cog/abstraction/impl/file/dcache/FileResourceImpl.java 2007-08-23 18:52:45 UTC (rev 1710)
+++ trunk/current/src/cog/modules/provider-dcache/src/org/globus/cog/abstraction/impl/file/dcache/FileResourceImpl.java 2007-08-23 18:56:23 UTC (rev 1711)
@@ -16,92 +16,98 @@
* enables access to local file system through the file resource interface
* Supports absolute and relative path names
*/
-public class FileResourceImpl extends org.globus.cog.abstraction.impl.file.local.FileResourceImpl {
- public static final Logger logger = Logger.getLogger(FileResourceImpl.class);
+public class FileResourceImpl extends
+ org.globus.cog.abstraction.impl.file.local.FileResourceImpl {
+ public static final Logger logger = Logger
+ .getLogger(FileResourceImpl.class);
- public static final String PROPERTIES = "provider-dcache.properties";
- public static final String DCCP = "dccp";
- public static final String OPTIONS = "dccp.options";
- private static Properties properties;
+ public static final String PROPERTIES = "provider-dcache.properties";
+ public static final String DCCP = "dccp";
+ public static final String OPTIONS = "dccp.options";
+ private static Properties properties;
- protected synchronized static Properties getProperties() {
- if (properties == null) {
- properties = new Properties();
- properties.put(DCCP, "dccp");
- properties.put(OPTIONS, "-d 1");
- URL res = FileResourceImpl.class.getClassLoader().getResource(PROPERTIES);
- if (res != null) {
- try {
- properties.load(res.openStream());
- }
- catch (IOException e) {
- logger.warn("Failed to load dcache provider properties", e);
- }
- }
- }
- return properties;
- }
+ protected synchronized static Properties getProperties() {
+ if (properties == null) {
+ properties = new Properties();
+ properties.put(DCCP, "dccp");
+ properties.put(OPTIONS, "-d 1");
+ URL res = FileResourceImpl.class.getClassLoader().getResource(
+ PROPERTIES);
+ if (res != null) {
+ try {
+ properties.load(res.openStream());
+ } catch (IOException e) {
+ logger.warn("Failed to load dcache provider properties",
+ e);
+ }
+ }
+ }
+ return properties;
+ }
- private static String[] dccpCmd;
+ private static String[] dccpCmd;
- protected synchronized static String[] getDCCPCmd() {
- if (dccpCmd == null) {
- StringTokenizer st = new StringTokenizer(getProperties().getProperty(OPTIONS));
- dccpCmd = new String[st.countTokens() + 1];
- dccpCmd[0] = getProperties().getProperty(DCCP);
- for (int i = 0; i < dccpCmd.length; i++) {
- dccpCmd[i + 1] = st.nextToken();
- }
- }
- return dccpCmd;
- }
+ protected synchronized static String[] getDCCPCmd() {
+ if (dccpCmd == null) {
+ StringTokenizer st = new StringTokenizer(getProperties()
+ .getProperty(OPTIONS));
+ dccpCmd = new String[st.countTokens() + 1];
+ dccpCmd[0] = getProperties().getProperty(DCCP);
+ for (int i = 0; i < dccpCmd.length; i++) {
+ dccpCmd[i + 1] = st.nextToken();
+ }
+ }
+ return dccpCmd;
+ }
- public FileResourceImpl() {
- this("dcache");
- }
+ public FileResourceImpl() {
+ this("dcache");
+ }
- public FileResourceImpl(String name) {
- super(name);
- }
+ public FileResourceImpl(String name) {
+ super(name);
+ }
- public void getFile(String remoteFileName, String localFileName, ProgressMonitor progressMonitor)
- throws FileResourceException {
- try {
- String[] opts = getDCCPCmd();
- String[] cmd = new String[opts.length + 2];
- System.arraycopy(opts, 0, cmd, 0, opts.length);
- cmd[cmd.length - 2] = resolve(remoteFileName).getAbsolutePath();
- cmd[cmd.length - 1] = resolve(localFileName).getAbsolutePath();
- Process p = Runtime.getRuntime().exec(cmd);
- consumeOutput(p);
- int exitcode = p.waitFor();
- if (exitcode != 0) {
- throw new FileResourceException("Failed to copy \"" + remoteFileName + "\" to \""
- + localFileName + "\". dccp failed with an exit code of " + exitcode);
- }
- }
- catch (FileResourceException e) {
- throw e;
- }
- catch (Exception e) {
- throw new FileResourceException(e);
- }
- }
+ public void getFile(String remoteFileName, String localFileName,
+ ProgressMonitor progressMonitor) throws FileResourceException {
+ try {
+ String[] opts = getDCCPCmd();
+ String[] cmd = new String[opts.length + 2];
+ System.arraycopy(opts, 0, cmd, 0, opts.length);
+ cmd[cmd.length - 2] = resolve(remoteFileName).getAbsolutePath();
+ cmd[cmd.length - 1] = resolve(localFileName).getAbsolutePath();
+ Process p = Runtime.getRuntime().exec(cmd);
+ String stderr = consumeOutput(p);
+ int exitcode = p.waitFor();
+ if (exitcode != 0) {
+ throw new FileResourceException("Failed to copy \""
+ + remoteFileName + "\" to \"" + localFileName
+ + "\". dccp failed with an exit code of " + exitcode
+ + ": " + stderr);
+ }
+ } catch (FileResourceException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new FileResourceException(e);
+ }
+ }
- private String consumeOutput(Process p) throws IOException {
- StringBuffer errstr = new StringBuffer();
- Reader out = new InputStreamReader(p.getInputStream());
- BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+ private String consumeOutput(Process p) throws IOException {
+ StringBuffer errstr = new StringBuffer();
+ Reader out = new InputStreamReader(p.getInputStream());
+ BufferedReader err = new BufferedReader(new InputStreamReader(p
+ .getErrorStream()));
- while (out.read() != -1) {
- // keep reading
- }
+ while (out.read() != -1) {
+ // keep reading
+ }
- String line = err.readLine();
- while (line != null) {
- errstr.append(line);
- errstr.append('\n');
- }
- return errstr.toString();
- }
+ String line = err.readLine();
+ while (line != null) {
+ errstr.append(line);
+ errstr.append('\n');
+ line = err.readLine();
+ }
+ return errstr.toString();
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|