Java Code Examples for java.io.File.separatorChar()

The following are Jave code examples for showing how to use separatorChar() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: dead-code-detector   File: DeadCodeDetector.java   View Source Code Vote up 6 votes
private Set<String> listClassesAndAnalyzeSubDirectories(String dir, String packageName)
		throws IOException, XMLStreamException {
	final Set<String> classNameList = new LinkedHashSet<>();
	final String directory;
	if (packageName == null) {
		directory = dir;
	} else {
		directory = dir + File.separatorChar + packageName.replace('.', File.separatorChar);
	}
	for (final File file : DcdHelper.listFiles(new File(directory))) {
		if (isInterrupted()) {
			break;
		}
		final String fileName = file.getName();
		final String name = packageName != null ? packageName + '.' + fileName : fileName;
		if (file.isDirectory() && fileName.indexOf('.') == -1) {
			analyzeDirectory(dir, name);
		} else if (fileName.endsWith(".class")) {
			classNameList.add(name.substring(0, name.length() - ".class".length()));
		}
	}
	return classNameList;
}
 
Example 2
Project: jdk8u-jdk   File: ConcurrentRead.java   View Source Code Vote up 6 votes
public static void main(String[] args) throws Exception {

        if (File.separatorChar == '\\' ||                // Windows
                                !new File(TEE).exists()) // no tee
            return;

        Process p = Runtime.getRuntime().exec(TEE);
        OutputStream out = p.getOutputStream();
        InputStream in = p.getInputStream();
        Thread t1 = new WriterThread(out, in);
        t1.start();
        Thread t2 = new WriterThread(out, in);
        t2.start();
        t1.join();
        t2.join();
        if (savedException != null)
            throw savedException;
    }
 
Example 3
Project: incubator-netbeans   File: DerbyDatabasesImpl.java   View Source Code Vote up 6 votes
/**
 * Returns the code point of the first illegal character in the given database
 * name.
 *
 * @return the code point of the first illegal character or -1 if all characters
 *         are valid.
 *
 * @throws NullPointerException if <code>databaseName</code> is null.
 */
public  int getFirstIllegalCharacter(String databaseName) {
    if (databaseName == null) {
        throw new NullPointerException("The databaseName parameter cannot be null"); // NOI18N
    }

    for (int i = 0; i < databaseName.length(); i++) {
        char ch = databaseName.charAt(i);
        if (ch == '/') {
            return (int)ch;
        }
        if (ch == File.separatorChar) {
            return (int)ch;
        }
    }

    return -1;
}
 
Example 4
Project: java-memory-assistant   File: E2eITest.java   View Source Code Vote up 5 votes
private String getHookScriptName() {
  final String scriptName = "hook."
      + (System.getProperty("os.name").toLowerCase().startsWith("win") ? "bat" : "sh");
  return "'src" + File.separatorChar + "test" + //
      File.separatorChar + "resources" + //
      File.separatorChar + "scripts" + //
      File.separatorChar + scriptName + "'";
}
 
Example 5
Project: jaffa-framework   File: UserGridManager.java   View Source Code Vote up 5 votes
/** determines using path for marshalling and unmarshalling the XML files from teh config files
 * @param userFile true if we want the user-specific file, else the default file.
 * @param userId user ID
 * @param userGridId user Grid Id
 * @return returns location string
 */
private static String getFileLocation(boolean userFile, String userId, String userGridId) {
    String root = null;
    // Get root location of setting files
    if (userFile) {
        root = (String) Config.getProperty(Config.PROP_USER_GRID_SETTINGS_URI, DEFAULT_SETTINGS_LOCATION);
    } else {
        root = (String) Config.getProperty(Config.PROP_DEFAULT_GRID_SETTINGS_URI, DEFAULT_SETTINGS_LOCATION);
    }

    // Make sure the directory seperator is always '/' as this is a url.
    if (root.startsWith("file:") && File.separatorChar != URL_CHAR) {
        root.replace(File.separatorChar, URL_CHAR);
    }

    String encodedUserId = userId;
    if(userId!=null) {
        try {
            encodedUserId = URLEncoder.encode(userId, "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            log.error("UserId encoding error.", ex);
        }
    }
    // build url
    if (userFile) {
        return root + (root.endsWith(URL_STRING) ? "" : URL_STRING) + encodedUserId + URL_STRING + "UGW_" + userGridId + ".xml";
    } else {
        return root + (root.endsWith("" + URL_STRING) ? "" : URL_STRING) + "UGW_" + userGridId + ".xml";
    }
}
 
Example 6
Project: incubator-netbeans   File: Evaluator.java   View Source Code Vote up 5 votes
/**
 * Gives a map from test type (e.g. <em>unit</em> or <em>qa-functional</em>)
 * to the {@link TestClasspath test classpath} according to the content in
 * the project's metadata (<em>project.xml<em>).
 */
private Map<String,TestClasspath> computeTestingClassPaths(ModuleList ml, PropertyEvaluator evaluator, Set<String> extraTestTypes) {
    Map<String, TestClasspath> classpaths = new HashMap<String,TestClasspath>();
    ProjectXMLManager pxm = new ProjectXMLManager(project);
    Map<String, Set<TestModuleDependency>> testDependencies = pxm.getTestDependencies(ml);
    
    String testDistDir =  evaluator.getProperty("test.dist.dir"); // NOI18N
    if (testDistDir == null) {
        NbModuleType type = project.getModuleType();
        if (type == NbModuleType.NETBEANS_ORG) {
            // test.dist.dir = ${nb_all}/nbbuild/build/testdist
            String nball = evaluator.getProperty("nb_all"); // NOI18N
            testDistDir = nball + File.separatorChar + "nbbuild" + File.separatorChar + "build" + File.separatorChar + "testdist"; // NOI18N
        } else if ( type == NbModuleType.SUITE_COMPONENT) {
            // test.dist.dir = ${suite.build.dir}/testdist
            String suiteDir = evaluator.getProperty("suite.build.dir"); // NOI18N
            testDistDir = suiteDir + File.separatorChar + "testdist"; // NOI18N
        } else {
            // standalone module
            // test.dist.dir = ${build.dir}/testdist
            String moduleDir = evaluator.getProperty("build.dir"); // NOI18N
            testDistDir = moduleDir + File.separatorChar + "testdist"; // NOI18N
        }
    }
    for (Map.Entry<String,Set<TestModuleDependency>> entry : testDependencies.entrySet()) {
        computeTestType(entry.getKey(), new File(testDistDir), entry.getValue(), classpaths, ml);
    }
    for (String testType : extraTestTypes) {
        if (!testDependencies.containsKey(testType)) {
            // No declared dependencies of this type, so will definitely need to add in compatibility libraries.
            computeTestType(testType, new File(testDistDir), Collections.<TestModuleDependency>emptySet(), classpaths, ml);
        }
    }
    return classpaths;
}
 
Example 7
Project: jdk8u-jdk   File: ICC_Profile.java   View Source Code Vote up 5 votes
/**
 * Returns a file object corresponding to a built-in profile
 * specified by fileName.
 * If there is no built-in profile with such name, then the method
 * returns null.
 */
private static File getStandardProfileFile(String fileName) {
    String dir = System.getProperty("java.home") +
        File.separatorChar + "lib" + File.separatorChar + "cmm";
    String fullPath = dir + File.separatorChar + fileName;
    File f = new File(fullPath);
    return (f.isFile() && isChildOf(f, dir)) ? f : null;
}
 
Example 8
Project: oscm   File: LoggerFactory.java   View Source Code Vote up 5 votes
private static void initAppenders() throws IOException {
    systemLogAppender = new RollingFileAppender(getLayout(), logFilePath
            + File.separatorChar + "system.log");
    accessLogAppender = new RollingFileAppender(getLayout(), logFilePath
            + File.separatorChar + "access.log");
    auditLogAppender = new RollingFileAppender(getLayout(), logFilePath
            + File.separatorChar + "audit.log");
    reverseProxyLogAppender = new RollingFileAppender(getLayout(),
            logFilePath + File.separatorChar + "reverseproxy.log");

    // setting the max backup index and file size
    systemLogAppender.setMaxBackupIndex(MAX_BACKUP_INDEX);
    systemLogAppender.setMaxFileSize(MAX_FILE_SIZE);
    systemLogAppender.setName(systemLogAppenderName);

    accessLogAppender.setMaxBackupIndex(MAX_BACKUP_INDEX);
    accessLogAppender.setMaxFileSize(MAX_FILE_SIZE);
    accessLogAppender.setName(accessLogAppenderName);

    auditLogAppender.setMaxBackupIndex(MAX_BACKUP_INDEX);
    auditLogAppender.setMaxFileSize(MAX_FILE_SIZE);
    auditLogAppender.setName(auditLogAppenderName);

    reverseProxyLogAppender.setMaxBackupIndex(MAX_BACKUP_INDEX);
    reverseProxyLogAppender.setMaxFileSize(MAX_FILE_SIZE);
    reverseProxyLogAppender.setName(reverseProxyLogAppenderName);
}
 
Example 9
Project: jdk8u-jdk   File: NIOCharsetAvailabilityTest.java   View Source Code Vote up 5 votes
/**
 * Walk through CLASSPATH and find class list from a package.
 * The class names start with prefix string
 * @param package name, class name prefix
 * @return class list in an array of String
 */
private static String[] getClassList(String pkgName, String prefix) {
    Vector listBuffer = new Vector();
    String packagePath = pkgName.replace('.', File.separatorChar)
        + File.separatorChar;
    String zipPackagePath = pkgName.replace('.', ZIPSEPARATOR)
        + ZIPSEPARATOR;
    for (int i = 0; i < classPathSegments.size(); i++){
        String onePath = (String) classPathSegments.elementAt(i);
        File f = new File(onePath);
        if (!f.exists())
            continue;
        if (f.isFile())
            scanFile(f, zipPackagePath, listBuffer, prefix);
        else if (f.isDirectory()) {
            String fullPath;
            if (onePath.endsWith(File.separator))
                fullPath = onePath + packagePath;
            else
                fullPath = onePath + File.separatorChar + packagePath;
            File dir = new File(fullPath);
            if (dir.exists() && dir.isDirectory())
                scanDir(dir, listBuffer, prefix);
        }
    }
    String[] classNames = new String[listBuffer.size()];
    listBuffer.copyInto(classNames);
    return classNames;
}
 
Example 10
Project: jdk8u-jdk   File: FileSystemView.java   View Source Code Vote up 5 votes
public static FileSystemView getFileSystemView() {
    if(File.separatorChar == '\\') {
        if(windowsFileSystemView == null) {
            windowsFileSystemView = new WindowsFileSystemView();
        }
        return windowsFileSystemView;
    }

    if(File.separatorChar == '/') {
        if(unixFileSystemView == null) {
            unixFileSystemView = new UnixFileSystemView();
        }
        return unixFileSystemView;
    }

    // if(File.separatorChar == ':') {
    //    if(macFileSystemView == null) {
    //      macFileSystemView = new MacFileSystemView();
    //    }
    //    return macFileSystemView;
    //}

    if(genericFileSystemView == null) {
        genericFileSystemView = new GenericFileSystemView();
    }
    return genericFileSystemView;
}
 
Example 11
Project: aos-MediaLib   File: VobHandler.java   View Source Code Vote up 5 votes
/**
 * counts the amount of '/' in a String
 */
private static int slashCount(String path) {
    if (path == null) return 0;
    int ret = 0;
    for (int i = 0; i < path.length(); i++) {
        if (path.charAt(i) == File.separatorChar) {
            ret ++;
        }
    }
    return ret;
}
 
Example 12
Project: dble   File: SystemConfig.java   View Source Code Vote up 5 votes
public SystemConfig() {
    this.serverPort = DEFAULT_PORT;
    this.managerPort = DEFAULT_MANAGER_PORT;
    this.serverBacklog = DEFAULT_BACK_LOG_SIZE;
    this.charset = DEFAULT_CHARSET;
    this.processors = DEFAULT_PROCESSORS;
    this.bufferPoolPageSize = DEFAULT_BUFFER_POOL_PAGE_SIZE;
    this.bufferPoolChunkSize = DEFAULT_BUFFER_CHUNK_SIZE;
    // if always big result,need large network buffer pool pages.
    this.bufferPoolPageNumber = (short) (DEFAULT_PROCESSORS * 20);

    this.processorExecutor = (DEFAULT_PROCESSORS != 1) ? DEFAULT_PROCESSORS * 2 : 4;

    this.idleTimeout = DEFAULT_IDLE_TIMEOUT;
    this.processorCheckPeriod = DEFAULT_PROCESSOR_CHECK_PERIOD;
    this.xaSessionCheckPeriod = DEFAULT_XA_SESSION_CHECK_PERIOD;
    this.xaLogCleanPeriod = DEFAULT_XA_LOG_CLEAN_PERIOD;
    this.dataNodeIdleCheckPeriod = DEFAULT_DATA_NODE_IDLE_CHECK_PERIOD;
    this.dataNodeHeartbeatPeriod = DEFAULT_DATA_NODE_HEARTBEAT_PERIOD;
    this.clusterHeartbeatUser = DEFAULT_CLUSTER_HEARTBEAT_USER;
    this.clusterHeartbeatPass = DEFAULT_CLUSTER_HEARTBEAT_PASS;
    this.txIsolation = Isolations.REPEATABLE_READ;
    this.sqlRecordCount = DEFAULT_SQL_RECORD_COUNT;
    this.glableTableCheckPeriod = DEFAULT_GLOBAL_TABLE_CHECK_PERIOD;
    this.xaRecoveryLogBaseDir = SystemConfig.getHomePath() + "/tmlogs/";
    this.xaRecoveryLogBaseName = "tmlog";
    this.viewPersistenceConfBaseDir = SystemConfig.getHomePath() + "/viewConf/";
    this.viewPersistenceConfBaseName = "viewJson";
    this.transactionLogBaseDir = SystemConfig.getHomePath() + File.separatorChar + DEFAULT_TRANSACTION_BASE_DIR;
    this.transactionLogBaseName = DEFAULT_TRANSACTION_BASE_NAME;
    this.transactionRatateSize = DEFAULT_TRANSACTION_ROTATE_SIZE;
    this.mergeQueueSize = DEFAULT_MERGE_QUEUE_SIZE;
    this.orderByQueueSize = DEFAULT_ORDER_BY_QUEUE_SIZE;
    this.joinQueueSize = DEFAULT_JOIN_QUEUE_SIZE;
    this.nestLoopRowsSize = DEFAULT_NEST_LOOP_ROWS_SIZE;
    this.nestLoopConnSize = DEFAULT_NEST_LOOP_CONN_SIZE;
    this.mappedFileSize = DEFAULT_MAPPED_FILE_SIZE;
    this.useJoinStrategy = DEFAULT_USE_JOIN_STRATEGY;
}
 
Example 13
Project: incubator-netbeans   File: HintTest.java   View Source Code Vote up 5 votes
private static String getWorkDirPathFromManager() {
    String path = System.getProperty(NBJUNIT_WORKDIR);
            
    if (path == null) {            
        // try to get property from user's settings
        path = readProperties().getProperty(NBJUNIT_WORKDIR);
    }
    if (path != null) {
        path = path.replace('/', File.separatorChar);
    } else {
        // Fallback value, guaranteed to be defined.
        path = System.getProperty("java.io.tmpdir") + File.separatorChar + "tests-" + System.getProperty("user.name");
    }
    return path;
}
 
Example 14
Project: incubator-netbeans   File: DockerConfig.java   View Source Code Vote up 5 votes
private static File getNewConfigFile() {
    String configPath = System.getenv("DOCKER_CONFIG");
    if (configPath == null) {
        configPath = System.getProperty("user.home") + File.separatorChar + ".docker";
    }

    return new File(configPath, "config.json");
}
 
Example 15
Project: incubator-netbeans   File: NewClustersRebootCallback.java   View Source Code Vote up 5 votes
private static void createFileWithNewClustersForNbexec(File newCluster, String nbdirs, File udir) throws FileNotFoundException, IOException {
    newCluster.mkdirs();
    nbdirs = nbdirs + File.pathSeparatorChar + newCluster.getAbsolutePath();
    File fileWithClustersForShell = new File(udir, "update"+File.separatorChar+"download"+File.separatorChar+"netbeans.dirs");
    fileWithClustersForShell.getParentFile().mkdirs();
    fileWithClustersForShell.createNewFile();
    OutputStream os = new FileOutputStream(fileWithClustersForShell);
    os.write(nbdirs.getBytes());
    os.close();
}
 
Example 16
Project: openjdk-jdk10   File: ToURL.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
    if (File.separatorChar == '/') {
        go("/");
    } else if (File.separatorChar == '\\') {
        go("\\");
        go("c:\\");
    }
}
 
Example 17
Project: BiglyBT   File: DiskManagerImpl.java   View Source Code Vote up 4 votes
/** Deletes all data files associated with torrent.
       * Currently, deletes all files, then tries to delete the path recursively
       * if the paths are empty.  An unexpected result may be that a empty
       * directory that the user created will be removed.
       *
       * TODO: only remove empty directories that are created for the torrent
       */

public static void
deleteDataFiles(
    TOTorrent   torrent,
    String      torrent_save_dir,       // enclosing dir, not for deletion
    String      torrent_save_file, 		// file or dir for torrent
    boolean		force_no_recycle )
{
    if (torrent == null || torrent_save_file == null ){

        return;
    }

    try{
        if (torrent.isSimpleTorrent()){

            File    target = new File( torrent_save_dir, torrent_save_file );

            target = FMFileManagerFactory.getSingleton().getFileLink( torrent, 0, target.getCanonicalFile());

            FileUtil.deleteWithRecycle( target, force_no_recycle );

        }else{

            PlatformManager mgr = PlatformManagerFactory.getPlatformManager();
            if( Constants.isOSX &&
                  torrent_save_file.length() > 0 &&
                  COConfigurationManager.getBooleanParameter("Move Deleted Data To Recycle Bin" ) &&
            		(! force_no_recycle ) &&
                  mgr.hasCapability(PlatformManagerCapabilities.RecoverableFileDelete) ) {

                try
                {
                    String  dir = torrent_save_dir + File.separatorChar + torrent_save_file + File.separatorChar;

                        // only delete the dir if there's only this torrent's files in it!

                    int numDataFiles = countDataFiles( torrent, torrent_save_dir, torrent_save_file );
                    if ( countFiles( new File(dir), numDataFiles) == numDataFiles){

                        mgr.performRecoverableFileDelete( dir );

                    }else{

                        deleteDataFileContents( torrent, torrent_save_dir, torrent_save_file, force_no_recycle );
                }
                }
                catch(PlatformManagerException ex)
                {
                    deleteDataFileContents( torrent, torrent_save_dir, torrent_save_file, force_no_recycle );
                }
            }
            else{
                deleteDataFileContents(torrent, torrent_save_dir, torrent_save_file, force_no_recycle);
            }

        }
    }catch( Throwable e ){

        Debug.printStackTrace( e );
    }
}
 
Example 18
Project: OpenVertretung   File: SyntaxRegressionTest.java   View Source Code Vote up 4 votes
/**
 * CREATE TABLE syntax changed in 5.6GA
 * 
 * InnoDB: Allow the location of file-per-table tablespaces to be chosen
 * CREATE TABLE ... DATA DIRECTORY = 'absolute/path/to/directory/'
 * 
 * Notes:
 * - DATA DIRECTORY option can't be used with temporary tables.
 * - DATA DIRECTORY and INDEX DIRECTORY can't be used together for InnoDB.
 * - Using these options result in an 'option ignored' warning for servers below MySQL 5.7.7. This syntax isn't allowed for MySQL 5.7.7 and higher.
 * 
 * @throws SQLException
 */
public void testCreateTableDataDirectory() throws SQLException {

    if (versionMeetsMinimum(5, 6, 6)) {
        try {
            String tmpdir = null;
            String separator = File.separatorChar == '\\' ? File.separator + File.separator : File.separator;
            this.rs = this.stmt.executeQuery("SHOW VARIABLES WHERE Variable_name='tmpdir' or Variable_name='innodb_file_per_table'");
            while (this.rs.next()) {
                if ("tmpdir".equals(this.rs.getString(1))) {
                    tmpdir = this.rs.getString(2);
                    if (tmpdir.endsWith(File.separator)) {
                        tmpdir = tmpdir.substring(0, tmpdir.length() - 1);
                    }
                    if (File.separatorChar == '\\') {
                        tmpdir = StringUtils.escapeQuote(tmpdir, File.separator);
                    }
                } else if ("innodb_file_per_table".equals(this.rs.getString(1))) {
                    if (!this.rs.getString(2).equals("ON")) {
                        fail("You need to set innodb_file_per_table to ON before running this test!");
                    }
                }
            }

            dropTable("testCreateTableDataDirectorya");
            dropTable("testCreateTableDataDirectoryb");
            dropTable("testCreateTableDataDirectoryc");
            dropTable("testCreateTableDataDirectoryd");

            createTable("testCreateTableDataDirectorya", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'");
            createTable("testCreateTableDataDirectoryb", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator + "'");
            this.stmt.executeUpdate("CREATE TEMPORARY TABLE testCreateTableDataDirectoryc (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir
                    + (versionMeetsMinimum(5, 7, 7) ? "' ENGINE = MyISAM" : "'"));
            createTable("testCreateTableDataDirectoryd", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator
                    + "' INDEX DIRECTORY = '" + tmpdir + (versionMeetsMinimum(5, 7, 7) ? "' ENGINE = MyISAM" : "'"));

            this.stmt.executeUpdate("ALTER TABLE testCreateTableDataDirectorya DISCARD TABLESPACE");

            this.pstmt = this.conn
                    .prepareStatement("CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'");
            assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);

            this.pstmt = this.conn.prepareStatement(
                    "CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator + "'");
            assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);

            this.pstmt = this.conn.prepareStatement(
                    "CREATE TEMPORARY TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'");
            assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);

            this.pstmt = this.conn.prepareStatement("CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '"
                    + tmpdir + "' INDEX DIRECTORY = '" + tmpdir + "'");
            assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);

            this.pstmt = this.conn.prepareStatement("ALTER TABLE testCreateTableDataDirectorya DISCARD TABLESPACE");
            assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);

        } finally {
            // we need to drop them even if retainArtifacts=true, otherwise temp files could be deleted by OS and DB became corrupted
            dropTable("testCreateTableDataDirectorya");
            dropTable("testCreateTableDataDirectoryb");
            dropTable("testCreateTableDataDirectoryc");
            dropTable("testCreateTableDataDirectoryd");
        }

    }
}
 
Example 19
Project: lams   File: DefaultServlet.java   View Source Code Vote up 4 votes
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    String path = getPath(req);
    if (!isAllowed(path, req.getDispatcherType())) {
        resp.sendError(StatusCodes.NOT_FOUND);
        return;
    }
    if(File.separatorChar != '/') {
        //if the separator char is not / we want to replace it with a / and canonicalise
        path = CanonicalPathUtils.canonicalize(path.replace(File.separatorChar, '/'));
    }
    final Resource resource;
    //we want to disallow windows characters in the path
    if(File.separatorChar == '/' || !path.contains(File.separator)) {
        resource = resourceManager.getResource(path);
    } else {
        resource = null;
    }

    if (resource == null) {
        if (req.getDispatcherType() == DispatcherType.INCLUDE) {
            //servlet 9.3
            throw new FileNotFoundException(path);
        } else {
            resp.sendError(StatusCodes.NOT_FOUND);
        }
        return;
    } else if (resource.isDirectory()) {
        if ("css".equals(req.getQueryString())) {
            resp.setContentType("text/css");
            resp.getWriter().write(DirectoryUtils.Blobs.FILE_CSS);
            return;
        } else if ("js".equals(req.getQueryString())) {
            resp.setContentType("application/javascript");
            resp.getWriter().write(DirectoryUtils.Blobs.FILE_JS);
            return;
        }
        if (directoryListingEnabled) {
            StringBuilder output = DirectoryUtils.renderDirectoryListing(req.getRequestURI(), resource);
            resp.getWriter().write(output.toString());
        } else {
            resp.sendError(StatusCodes.FORBIDDEN);
        }
    } else {
        if(path.endsWith("/")) {
            //UNDERTOW-432
            resp.sendError(StatusCodes.NOT_FOUND);
            return;
        }
        serveFileBlocking(req, resp, resource);
    }
}
 
Example 20
Project: manifold   File: ManFileExt.java   View Source Code Vote up 4 votes
/**
 * Returns [path] of this File using the invariant separator '/' to
 * separate the names in the name sequence.
 */
public static String slashPath( @This File thiz )
{
  return File.separatorChar != '/' ? thiz.getPath().replace( File.separatorChar, '/' ) : thiz.getPath();
}