Example usage for java.io File separatorChar

List of usage examples for java.io File separatorChar

Introduction

In this page you can find the example usage for java.io File separatorChar.

Prototype

char separatorChar

To view the source code for java.io File separatorChar.

Click Source Link

Document

The system-dependent default name-separator character.

Usage

From source file:common.AbstractGUI.java

protected void saveLogTo(File file, String text) {
    File logFile = new File(
            file.getPath() + File.separatorChar + getName() + "-log-" + System.currentTimeMillis() + ".log");
    try {/*  ww  w  . j a  va  2s.c o  m*/
        FileUtils.writeStringToFile(logFile, text);
    } catch (IOException e) {
        log(e.getMessage());
    }
}

From source file:architecture.ee.web.view.freemarker.ExtendedTemplateLoader.java

@Override
public Object findTemplateSource(String name) throws IOException {

    log.debug("searching... " + name + ", customized : " + isCustomizedEnabled());

    if (isCustomizedEnabled()) {
        try {//from   w  w  w  .ja  v  a2s . co  m
            MethodInvoker invoker = new MethodInvoker();
            invoker.setStaticMethod("architecture.ee.web.struts2.util.ActionUtils.getAction");
            invoker.prepare();
            Object action = invoker.invoke();
            if (action instanceof WebSiteAware) {
                WebSite site = ((WebSiteAware) action).getWebSite();
                String nameToUse = SEP_IS_SLASH ? name : name.replace('/', File.separatorChar);
                if (nameToUse.charAt(0) == File.separatorChar) {
                    nameToUse = File.separatorChar + "sites" + File.separatorChar + site.getName().toLowerCase()
                            + nameToUse;
                } else {
                    nameToUse = File.separatorChar + "sites" + File.separatorChar + site.getName().toLowerCase()
                            + File.separatorChar + nameToUse;
                }
                log.debug((new StringBuilder()).append("website:").append(site.getName().toLowerCase())
                        .append(", template: ").append(nameToUse).toString());
                File source = new File(baseDir, SEP_IS_SLASH ? name : name.replace('/', File.separatorChar));
                return super.findTemplateSource(nameToUse);
            }
        } catch (Exception e) {
            log.warn(e);
        }
    }
    return null;
    /*      if( usingDatabase() ){
             try {            
    MethodInvoker invoker = new MethodInvoker();      
    invoker.setStaticMethod("architecture.ee.web.struts2.util.ActionUtils.getAction");
    invoker.prepare();
    Object action = invoker.invoke();
            
    if( action instanceof TemplateAware ){
       Template template = ((TemplateAware)action).getTargetTemplate();
       if( log.isDebugEnabled() )
          log.debug( name + " < compare > template from action:" + template.getTitle() + ", type=" + template.getTemplateType() + ", locaion=" + template.getLocation());               
       if(  "ftl".equals(template.getTemplateType()) && name.contains(template.getLocation() ))
          return template;
    }
            
             } catch (Exception e) {
    log.warn(e);            
             }
             List<Template> contents = getCurrentCompanyTemplates();
             for( Template template : contents){
    if( log.isDebugEnabled() )
       log.debug( name + "< compare > template from database :" + template.getTitle() + ", type:" + template.getTemplateType() + ", match:" + template.getLocation() .contains(name) );
    if(  template.getLocation() .contains(name)){
       return template;
    }
             }         
          }   */
}

From source file:com.autentia.wuija.web.DownloadServlet.java

/**
 * Process GET request/*from w w  w  .j  a  v a  2s .  co  m*/
 * 
 * @param request HTTP request
 * @param response HTTP response
 * @throws javax.servlet.ServletException
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    final String requestUri = request.getRequestURI();
    final String fileName = requestUri.substring(requestUri.lastIndexOf('/') + 1, requestUri.length());

    if (log.isTraceEnabled()) {
        log.trace("fileName='" + fileName + "'.");
    }

    if (fileName == null) {
        final String msg = "Filename not found in the requested URL.";
        log.error(msg);
        throw new ServletException(msg);
    }

    final StringBuilder tempFilePath = new StringBuilder(System.getProperty("java.io.tmpdir"));

    if (log.isTraceEnabled()) {
        log.trace("tempdir = " + tempFilePath);
    }

    if (tempFilePath.charAt(tempFilePath.length() - 1) != File.separatorChar) {
        tempFilePath.append(File.separatorChar);
    }

    tempFilePath.append(fileName);

    if (log.isTraceEnabled()) {
        log.trace("filePath = " + tempFilePath);
    }

    final File file = new File(tempFilePath.toString());
    file.deleteOnExit();

    String clientFileName = request.getHeader(FILE_NAME);
    if (clientFileName == null) {
        clientFileName = file.getName();
    }
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Content-disposition", "attachment; filename=" + clientFileName);

    // XXX [wuija]: reemplazar por una librera de mimetypes
    if (clientFileName.toLowerCase().endsWith(".csv")) {
        response.setContentType("application/vnd.ms-excel");
    } else if (clientFileName.toLowerCase().endsWith(".zip")) {
        response.setContentType("application/zip");
    } else if (clientFileName.toLowerCase().endsWith(".pdf")) {
        response.setContentType("application/pdf");
    }
    response.setContentLength((int) file.length());

    try {
        int read = 0;
        final byte[] bytes = new byte[1024];
        final FileInputStream in = new FileInputStream(file);

        while ((read = in.read(bytes)) != -1) {
            response.getOutputStream().write(bytes, 0, read);
        }
        in.close();

        log.trace("The contents of the file have been written.");

        response.getOutputStream().flush();
        response.getOutputStream().close();
    } catch (IOException e) {
        final String msg = "Error writting the contents of the file.";
        log.error(msg);
        throw new ServletException(msg, e);
    }

    file.delete();
    log.trace("File='" + file + "' deleted.");

}

From source file:it.cilea.osd.jdyna.widget.WidgetFile.java

/**
 * Load file and copy to default directory.
 * /*from  ww  w.j a va 2  s.c o m*/
 * @param file
 */
public EmbeddedFile load(InputStream stream, String originalFilename, String contentType, String extAuthority,
        String intAuthority) throws IOException, FileNotFoundException {
    EmbeddedFile result = new EmbeddedFile();
    String folder = intAuthority;
    if (extAuthority != null && extAuthority.length() > 0) {
        folder = getCustomFolderByAuthority(extAuthority, intAuthority);
    }
    String fileName = "";
    String pathCV = getBasePath();
    String ext = null;
    File dir = new File(pathCV + File.separatorChar + folder);
    dir.mkdirs();
    File file = null;
    if (originalFilename.lastIndexOf(".") == -1) {
        fileName = originalFilename;
        file = new File(dir, fileName);
    } else {
        fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
        ext = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
        file = new File(dir, fileName + "." + ext);
    }

    int i = 1;
    while (!file.createNewFile()) {
        fileName = fileName + "_" + i;
        file = new File(dir, fileName + ((ext != null) ? ("." + ext) : ""));
        i++;
    }

    FileOutputStream out = new FileOutputStream(file);
    it.cilea.osd.common.util.Utils.bufferedCopy(stream, out);
    out.close();
    result.setValueFile(fileName);
    result.setExtFile(ext);
    result.setMimeFile(contentType);
    result.setFolderFile(folder);
    return result;
}

From source file:com.jaxio.celerio.maven.plugin.celerio.CleanGeneratedMojo.java

private String getProjectBaseDir() {
    return normalize(project.getBasedir().getAbsoluteFile().getAbsolutePath() + File.separatorChar);
}

From source file:com.wabacus.util.WabacusClassLoader.java

public synchronized Class loadClassFromClassPath(String className) {

    Iterator<String> dirs = classRepository.iterator();
    byte[] classBytes = null;

    while (dirs.hasNext()) {
        String dir = (String) dirs.next();

        String classFileName = className.replace('.', File.separatorChar);
        classFileName += ".class";
        try {//from  w ww. ja va 2 s. c  om
            File file = new File(dir + File.separatorChar + classFileName);
            if (file.exists()) {
                InputStream is = new FileInputStream(file);
                classBytes = new byte[is.available()];
                is.read(classBytes);
                break;
            }
        } catch (IOException ex) {

            ex.printStackTrace();
            return null;
        }
    }
    return this.defineClass(className, classBytes, 0, classBytes.length);
}

From source file:com.opensymphony.webwork.util.classloader.ReloadingClassLoader.java

public static String clazzName(final File base, final File file) {
    final int rootLength = base.getAbsolutePath().length();
    final String absFileName = file.getAbsolutePath();
    final int p = absFileName.lastIndexOf('.');
    final String relFileName = absFileName.substring(rootLength + 1, p);
    final String clazzName = relFileName.replace(File.separatorChar, '.');
    return clazzName;
}

From source file:it.openprj.jValidator.spring.ExtraCheckCustomCodeValidator.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String code = request.getParameter("value");
    String name = request.getParameter("name");
    String addReq = request.getParameter("addReq");

    //TODO: take the result message from "locale"
    String result = null;//from w w  w. ja  v a2  s . c  o m
    ObjectMapper mapper = new ObjectMapper();
    ServletOutputStream out = null;
    response.setContentType("application/json");
    out = response.getOutputStream();
    if (StringUtils.isEmpty(code) || StringUtils.isEmpty(name)) {
        result = I18n.getMessage("error.extracheck.invaliddata");
    } else {
        name = name.trim();
        if (addReq.equalsIgnoreCase("true")) {
            ReadList list = checksTypeDao.findCustomCodeByName(name);
            if (list != null && CollectionUtils.isNotEmpty(list.getResults())) {
                result = I18n.getMessage("error.extracheck.name.alreadyexist");
                out.write(mapper.writeValueAsBytes(result));
                out.flush();
                out.close();
                return null;
            }
        }
        try {
            File sourceDir = new File(System.getProperty("java.io.tmpdir"), "jValidator/src");
            sourceDir.mkdirs();
            String classNamePack = name.replace('.', File.separatorChar);
            String srcFilePath = sourceDir + "" + File.separatorChar + classNamePack + ".java";
            File sourceFile = new File(srcFilePath);
            if (sourceFile.exists()) {
                sourceFile.delete();
            }
            FileUtils.writeStringToFile(new File(srcFilePath), code);
            DynamicClassLoader dynacode = DynamicClassLoader.getInstance();
            dynacode.addSourceDir(sourceDir);
            CustomCodeValidator customCodeValidator = (CustomCodeValidator) dynacode
                    .newProxyInstance(CustomCodeValidator.class, name);
            boolean isValid = false;
            if (customCodeValidator != null) {
                Class clazz = dynacode.getLoadedClass(name);
                if (clazz != null) {
                    Class[] interfaces = clazz.getInterfaces();
                    if (ArrayUtils.isNotEmpty(interfaces)) {
                        for (Class clz : interfaces) {
                            if ((clz.getName().equalsIgnoreCase(
                                    "it.openprj.jValidator.utils.validation.SingleValidation"))) {
                                isValid = true;
                            }
                        }
                    }
                }
            }
            if (isValid) {
                result = "Success";
            } else {
                result = I18n.getMessage("error.extracheck.wrongimpl");
            }
        } catch (Exception e) {
            result = "Failed. Reason:" + e.getMessage();
        }
    }
    out.write(mapper.writeValueAsBytes(result));
    out.flush();
    out.close();
    return null;
}

From source file:de.tu_dortmund.ub.data.util.TPUUtil.java

public static String writeResultToFile(final CloseableHttpResponse httpResponse, final Properties config,
        final String exportDataModelID, final String fileEnding) throws IOException, TPUException {

    LOG.info("try to write result to file");

    final String persistInFolderString = config.getProperty(TPUStatics.PERSIST_IN_FOLDER_IDENTIFIER);
    final boolean persistInFolder = Boolean.parseBoolean(persistInFolderString);
    final HttpEntity entity = httpResponse.getEntity();

    final String fileName;

    if (persistInFolder) {

        final InputStream responseStream = entity.getContent();
        final BufferedInputStream bis = new BufferedInputStream(responseStream, 1024);

        final String resultsFolder = config.getProperty(TPUStatics.RESULTS_FOLDER_IDENTIFIER);
        fileName = resultsFolder + File.separatorChar + EXPORT_FILE_NAME_PREFIX + exportDataModelID + DOT
                + fileEnding;/*from   w  ww  .j  a  v  a 2  s .  c  o  m*/

        LOG.info(String.format("start writing result to file '%s'", fileName));

        final FileOutputStream outputStream = new FileOutputStream(fileName);
        final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);

        IOUtils.copy(bis, bufferedOutputStream);
        bufferedOutputStream.flush();
        outputStream.flush();
        bis.close();
        responseStream.close();
        bufferedOutputStream.close();
        outputStream.close();

        checkResultForError(fileName);
    } else {

        fileName = "[no file name available]";
    }

    EntityUtils.consume(entity);

    return fileName;
}

From source file:it.openprj.jValidator.spring.EventTriggerValidator.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String code = request.getParameter("code");
    String name = request.getParameter("name");
    String addReq = request.getParameter("addReq");

    String result = null;//  ww w .  j  a v  a2s  . c o  m

    ObjectMapper mapper = new ObjectMapper();
    ServletOutputStream out = null;
    response.setContentType("application/json");
    out = response.getOutputStream();

    if (StringUtils.isEmpty(code) || StringUtils.isEmpty(name)) {
        result = I18n.getMessage("error.trigger.invaliddata");//"Failed. Reason:Invalid Data";
    } else {
        name = name.trim();
        if (addReq.equalsIgnoreCase("true")) {
            ReadList list = eventTriggerDao.findTriggersByName(name);
            if (list != null && CollectionUtils.isNotEmpty(list.getResults())) {
                result = I18n.getMessage("error.trigger.name.alreadyexist");//"Failed. Reason:Name alredy exist";
                out.write(mapper.writeValueAsBytes(result));
                out.flush();
                out.close();
                return null;
            }
        }
        try {
            File sourceDir = new File(System.getProperty("java.io.tmpdir"), "jValidator/src");
            sourceDir.mkdirs();
            String classNamePack = name.replace('.', File.separatorChar);
            String srcFilePath = sourceDir + "" + File.separatorChar + classNamePack + ".java";
            File sourceFile = new File(srcFilePath);
            if (sourceFile.exists()) {
                sourceFile.delete();
            }
            FileUtils.writeStringToFile(new File(srcFilePath), code);
            DynamicClassLoader dynacode = DynamicClassLoader.getInstance();
            dynacode.addSourceDir(sourceDir);
            EventTrigger eventTrigger = (EventTrigger) dynacode.newProxyInstance(EventTrigger.class, name);
            boolean isValid = false;
            if (eventTrigger != null) {
                Class clazz = dynacode.getLoadedClass(name);
                if (clazz != null) {
                    Class[] interfaces = clazz.getInterfaces();
                    if (ArrayUtils.isNotEmpty(interfaces)) {
                        for (Class clz : interfaces) {
                            if (clz.getName()
                                    .equalsIgnoreCase("it.openprj.jValidator.eventtrigger.EventTrigger")) {
                                isValid = true;
                            }
                        }
                    } else if (clazz.getSuperclass() != null && clazz.getSuperclass().getName()
                            .equalsIgnoreCase("it.openprj.jValidator.eventtrigger.EventTriggerImpl")) {
                        isValid = true;
                    }
                }
            }
            if (isValid) {
                result = "Success";
            } else {
                result = I18n.getMessage("error.trigger.wrongimpl");//"Failed. Reason: Custom code should implement it.openprj.jValidator.eventtrigger.EventTrigger Interface";
            }
        } catch (Exception e) {
            result = "Failed. Reason:" + e.getMessage();
        }
    }
    out.write(mapper.writeValueAsBytes(result));
    out.flush();
    out.close();
    return null;
}