Class FileUtilities
- java.lang.Object
-
- ca.corefacility.bioinformatics.irida.ria.utilities.FileUtilities
-
public class FileUtilities extends java.lang.ObjectDownload a zip archive of all output files within anAnalysisSubmission
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringATTACHMENT_FILENAMEstatic java.lang.StringCONTENT_DISPOSITIONstatic java.lang.StringCONTENT_TYPE_APPLICATION_ZIPstatic java.lang.StringCONTENT_TYPE_TEXTstatic java.lang.StringEXTENSION_HTML_ZIPstatic java.lang.StringEXTENSION_ZIP
-
Constructor Summary
Constructors Constructor Description FileUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcreateAnalysisOutputFileZippedResponse(javax.servlet.http.HttpServletResponse response, java.lang.String fileName, java.util.Set<AnalysisOutputFile> files)Utility method for download a zip file containing all output files from an analysis.static voidcreateBatchAnalysisOutputFileZippedResponse(javax.servlet.http.HttpServletResponse response, java.lang.String fileName, java.util.Map<ProjectSampleAnalysisOutputInfo,AnalysisOutputFile> files)Utility method for download a zip file containing all output files from an analysis.static voidcreateSingleFileResponse(javax.servlet.http.HttpServletResponse response, AnalysisOutputFile file)Utility method for download single file from an analysis.static voidcreateSingleFileResponse(javax.servlet.http.HttpServletResponse response, AnalysisOutputFile file, java.lang.String fileName)Utility method for download single file from an analysis.static java.util.List<java.lang.String>getExcelSheetNames(org.apache.poi.ss.usermodel.Workbook workbook)Extract the sheet names from the excel workbookstatic java.lang.StringgetFileExt(java.nio.file.Path filepath)Get file extension from filepath.static java.lang.StringgetUniqueFilename(java.nio.file.Path filePath, java.lang.String sampleName, java.lang.Long sampleId, java.lang.Long analysisSubmissionId)Get a unique filename for a filePath from an analysis output file.static java.util.List<ExcelHeader>getWorkbookHeaders(org.apache.poi.ss.usermodel.Row row)Extract the headers from an excel file.static java.lang.StringhumanReadableByteCount(long bytes, boolean si)From (http://stackoverflow.com/questions/3758606/how-to-convert-byte-size- into-human-readable-format-in-java)static booleanisZippedFile(java.nio.file.Path path)Determine if a file is a zip file.static ExcelDataparseExcelFile(AnalysisOutputFile outputFile, int sheetIndex)Parse the data from anAnalysisOutputFileexcel file.static java.lang.StringreadChunk(java.io.RandomAccessFile raf, java.lang.Long seek, java.lang.Long chunk)Read bytes of lengthchunkof a file starting at byteseek.static java.util.List<java.lang.String>readLinesFromFilePointer(java.io.RandomAccessFile randomAccessFile, java.lang.Long limit)Read lines from file using aRandomAccessFile.static java.util.List<java.lang.String>readLinesLimit(java.io.BufferedReader reader, java.lang.Long limit, java.lang.Long start, java.lang.Long end)Read a specified number of lines from a file.
-
-
-
Field Detail
-
CONTENT_DISPOSITION
public static final java.lang.String CONTENT_DISPOSITION
- See Also:
- Constant Field Values
-
ATTACHMENT_FILENAME
public static final java.lang.String ATTACHMENT_FILENAME
- See Also:
- Constant Field Values
-
CONTENT_TYPE_APPLICATION_ZIP
public static final java.lang.String CONTENT_TYPE_APPLICATION_ZIP
- See Also:
- Constant Field Values
-
CONTENT_TYPE_TEXT
public static final java.lang.String CONTENT_TYPE_TEXT
- See Also:
- Constant Field Values
-
EXTENSION_ZIP
public static final java.lang.String EXTENSION_ZIP
- See Also:
- Constant Field Values
-
EXTENSION_HTML_ZIP
public static final java.lang.String EXTENSION_HTML_ZIP
- See Also:
- Constant Field Values
-
-
Method Detail
-
createAnalysisOutputFileZippedResponse
public static void createAnalysisOutputFileZippedResponse(javax.servlet.http.HttpServletResponse response, java.lang.String fileName, java.util.Set<AnalysisOutputFile> files)Utility method for download a zip file containing all output files from an analysis.- Parameters:
response-HttpServletResponsefileName- Name fo the file to createfiles- Set ofAnalysisOutputFile
-
createBatchAnalysisOutputFileZippedResponse
public static void createBatchAnalysisOutputFileZippedResponse(javax.servlet.http.HttpServletResponse response, java.lang.String fileName, java.util.Map<ProjectSampleAnalysisOutputInfo,AnalysisOutputFile> files)Utility method for download a zip file containing all output files from an analysis.- Parameters:
response-HttpServletResponsefileName- Name fo the file to createfiles- Set ofAnalysisOutputFile
-
createSingleFileResponse
public static void createSingleFileResponse(javax.servlet.http.HttpServletResponse response, AnalysisOutputFile file, java.lang.String fileName)Utility method for download single file from an analysis.- Parameters:
response-HttpServletResponsefile- Set ofAnalysisOutputFilefileName- Filename
-
createSingleFileResponse
public static void createSingleFileResponse(javax.servlet.http.HttpServletResponse response, AnalysisOutputFile file)Utility method for download single file from an analysis.- Parameters:
response-HttpServletResponsefile- Set ofAnalysisOutputFile
-
getFileExt
public static java.lang.String getFileExt(java.nio.file.Path filepath)
Get file extension from filepath.Uses simple regex to parse file extension
^.*\.(\w+)$.- Parameters:
filepath- ThePathof a file to retrieve ext.- Returns:
- File extension if found; otherwise empty string
-
getUniqueFilename
public static java.lang.String getUniqueFilename(java.nio.file.Path filePath, java.lang.String sampleName, java.lang.Long sampleId, java.lang.Long analysisSubmissionId)Get a unique filename for a filePath from an analysis output file.- Parameters:
filePath- ThePathof the file to generate a unique filename forsampleName- The name of theSampleassociated with the analysissampleId- The id of theSampleassociated with the analysisanalysisSubmissionId- The id of theAnalysisSubmissionthat generated the file- Returns:
- Unique filename of the format SAMPLENAME-sampleId-SAMPLEID-analysisSubmissionId-ANALYSISSUBMISSIONID-ORIGFILENAME
-
readChunk
public static java.lang.String readChunk(java.io.RandomAccessFile raf, java.lang.Long seek, java.lang.Long chunk) throws java.io.IOExceptionRead bytes of lengthchunkof a file starting at byteseek.- Parameters:
raf- File readerseek- FilePointer position to start reading atchunk- Number of bytes to read from file- Returns:
- Chunk of file as String
- Throws:
java.io.IOException- if error enountered while reading file
-
readLinesLimit
public static java.util.List<java.lang.String> readLinesLimit(java.io.BufferedReader reader, java.lang.Long limit, java.lang.Long start, java.lang.Long end)Read a specified number of lines from a file.- Parameters:
reader- File readerlimit- Limit to the number of lines to readstart- Optional line number to start reading atend- Optional line number to read up to- Returns:
- Lines read from file
-
readLinesFromFilePointer
public static java.util.List<java.lang.String> readLinesFromFilePointer(java.io.RandomAccessFile randomAccessFile, java.lang.Long limit) throws java.io.IOExceptionRead lines from file using aRandomAccessFile.Use this method if preserving the
RandomAccessFile.getFilePointer()for continuing reading is important. For most use cases,readLinesLimit(BufferedReader, Long, Long, Long)will perform better due to bufffered reading.- Parameters:
randomAccessFile- File readerlimit- Limit to the number of lines to read- Returns:
- Lines read from file
- Throws:
java.io.IOException- if error enountered while reading file
-
parseExcelFile
public static ExcelData parseExcelFile(AnalysisOutputFile outputFile, int sheetIndex)
Parse the data from anAnalysisOutputFileexcel file.- Parameters:
outputFile-AnalysisOutputFileThe excel file to parsesheetIndex- The index of the sheet to parse- Returns:
- parsed excel file data
-
getWorkbookHeaders
public static java.util.List<ExcelHeader> getWorkbookHeaders(org.apache.poi.ss.usermodel.Row row)
Extract the headers from an excel file.- Parameters:
row-RowFirst row from the excel file.- Returns:
ListofExcelHeaderheader values.
-
getExcelSheetNames
public static java.util.List<java.lang.String> getExcelSheetNames(org.apache.poi.ss.usermodel.Workbook workbook)
Extract the sheet names from the excel workbook- Parameters:
workbook-WorkbookThe excel workbook to get sheet names from- Returns:
ListofStringsheet names.
-
humanReadableByteCount
public static java.lang.String humanReadableByteCount(long bytes, boolean si)From (http://stackoverflow.com/questions/3758606/how-to-convert-byte-size- into-human-readable-format-in-java)- Parameters:
bytes- TheLongsize of the file in bytes.si-Booleantrue to use si units- Returns:
- A human readable
Stringrepresentation of the file size.
-
isZippedFile
public static boolean isZippedFile(java.nio.file.Path path) throws java.io.IOExceptionDetermine if a file is a zip file.- Parameters:
path- ThePathto the file to test.- Returns:
- A boolean indicating whether the file is a zip file.
- Throws:
java.io.IOException- If an invalidPathis passed
-
-