Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.devbliss.doctest.utils;
 
 import java.io.File;
 import java.io.Writer;
Defines some general methods to write a file and defines its name. Each com.devbliss.doctest.renderer.ReportRenderer must use this class to write the file and build its correct name.

Author(s):
bmary
public class FileHelper {

    
By convention we are using the maven project structure. Therefore doctest will be written into ./target/doctests/.
    private static final String OUTPUT_DIRECTORY = new File("").getAbsolutePath()
            + "/target/site/doctests/";

    
This writes out the file and retries if some other task has locked the file. This could cause a StackOverflowException, but I cannot think of any real case where this happens...

Parameters:
nameOfFile
Throws:
InvalidReportException
    public void writeFile(String nameCompletePathString finalDoc) {
        // make sure the directory exists
        new File(nameCompletePath).getParentFile().mkdirs();
        writeOutFile(nameCompletePathfinalDoc);
    }
    private void writeOutFile(String nameOfFileString content) {
        Writer fw = null;
        if (content != null) {
            try {
                fw = new FileWriter(nameOfFile);
                fw.write(content);
            } catch (IOException e) {
                try {
                    Thread.sleep(200);
                    writeOutFile(nameOfFilecontent);
                } catch (InterruptedException err2) {
                    writeOutFile(nameOfFilecontent);
                }
            } finally {
                closeFileWriter(fw);
            }
        }
    }
    private void closeFileWriter(Writer fw) {
        if (fw != null) {
            try {
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public String getCompleteFileName(String nameString extension) {
        return  + name + extension;
    }
    public String readFile(File fileToUploadthrows IOException {
        FileInputStream stream = new FileInputStream(fileToUpload);
        try {
            FileChannel fc = stream.getChannel();
            MappedByteBuffer bb = fc.map(.., 0, fc.size());
            /* Instead of using default, pass in a decoder. */
            String body = Charset.defaultCharset().decode(bb).toString();
            return body.replaceAll("\n""<br/>");
        } finally {
            stream.close();
        }
    }
New to GrepCode? Check out our FAQ X