Java Unix Path unixPathToWindows(String strPath)

Here you can find the source of unixPathToWindows(String strPath)

Description

unix Path To Windows

License

GNU General Public License

Declaration

public static String unixPathToWindows(String strPath) 

Method Source Code

//package com.java2s;
/*//from  w  ww  .j av  a  2 s.  c  om
 * Copyright (C) 2015  University of Oregon
 *
 * You may distribute under the terms of either the GNU General Public
 * License or the Apache License, as specified in the LICENSE file.
 *
 * For more information, see the LICENSE file.
 */

public class Main {
    public static String OSNAME = System.getProperty("os.name");
    public static String SYSDIR = System.getProperty("sysdir");
    public static String SFUDIR_WINDOWS = System
            .getProperty("sfudirwindows");

    public static String unixPathToWindows(String strPath) {
        if (strPath == null || strPath.length() == 0 || OSNAME == null
                || !OSNAME.startsWith("Windows"))
            return strPath;

        StringBuffer sbPath = new StringBuffer(strPath.trim());
        String strunix = "/dev/fs/";
        int nIndex = sbPath.indexOf(strunix);
        int index = sbPath.indexOf("\\dev\\fs");
        if (strPath.indexOf(":") != 1) {
            // /vnmr might be symbolic link e.g. /vnmr
            if (strPath.equals("/vnmr") || strPath.startsWith("/vnmr/"))
                sbPath.replace(0, 5, SYSDIR);

            if (nIndex >= 0 || index >= 0) {
                // delete unix string
                sbPath.delete(0, strunix.length());

                // insert ':\' e.g. C:\ or ':' e.g C:
                if (sbPath.length() == 1)
                    //sbPath.insert(1, ":\\");
                    sbPath.insert(1, ":/");
                else if (sbPath.charAt(1) != ':')
                    sbPath.insert(1, ':');
            } else {
                // If it starts with /SFU, remove it
                if (sbPath.charAt(0) == '/')
                    sbPath.insert(0, SFUDIR_WINDOWS);
            }
        }
        // replace symbolic link with full path
        else if (strPath.indexOf("/SFU/vnmr") == 2)
            sbPath.replace(0, 11, SYSDIR);

        //replace '\' with '/'
        while ((nIndex = sbPath.indexOf("\\")) >= 0) {
            sbPath.replace(nIndex, nIndex + 1, "/");
        }
        while ((nIndex = sbPath.indexOf("//")) >= 0) {
            sbPath.replace(nIndex, nIndex + 2, "/");
        }

        return sbPath.toString();
    }
}

Related

  1. getUnixRelativePath(File base, File path)
  2. toUNIXfilePath(String fileName)
  3. unixizeWindowsAbsolutePath(final String pathToCheck)
  4. unixPath(String sText)
  5. unixPathStr(String anyPath)
  6. unixToUserPathName(String unixPathName)