Class FileUtilities
- java.lang.Object
-
- ca.corefacility.bioinformatics.irida.ria.utilities.FileUtilities
-
public class FileUtilities extends java.lang.Object
Download a zip archive of all output files within anAnalysisSubmission
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ATTACHMENT_FILENAME
static java.lang.String
CONTENT_DISPOSITION
static java.lang.String
CONTENT_TYPE_APPLICATION_ZIP
static java.lang.String
CONTENT_TYPE_TEXT
static java.lang.String
EXTENSION_HTML_ZIP
static java.lang.String
EXTENSION_ZIP
-
Constructor Summary
Constructors Constructor Description FileUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.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.static void
createSingleFileResponse(javax.servlet.http.HttpServletResponse response, AnalysisOutputFile file)
Utility method for download single file from an analysis.static void
createSingleFileResponse(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.String
getFileExt(java.nio.file.Path filepath)
Get file extension from filepath.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.static java.util.List<ExcelHeader>
getWorkbookHeaders(org.apache.poi.ss.usermodel.Row row)
Extract the headers from an excel file.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)static boolean
isZippedFile(java.nio.file.Path path)
Determine if a file is a zip file.static ExcelData
parseExcelFile(AnalysisOutputFile outputFile, int sheetIndex)
Parse the data from anAnalysisOutputFile
excel file.static java.lang.String
readChunk(java.io.RandomAccessFile raf, java.lang.Long seek, java.lang.Long chunk)
Read bytes of lengthchunk
of 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
-HttpServletResponse
fileName
- 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
-HttpServletResponse
fileName
- 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
-HttpServletResponse
file
- Set ofAnalysisOutputFile
fileName
- Filename
-
createSingleFileResponse
public static void createSingleFileResponse(javax.servlet.http.HttpServletResponse response, AnalysisOutputFile file)
Utility method for download single file from an analysis.- Parameters:
response
-HttpServletResponse
file
- 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
- ThePath
of 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
- ThePath
of the file to generate a unique filename forsampleName
- The name of theSample
associated with the analysissampleId
- The id of theSample
associated with the analysisanalysisSubmissionId
- The id of theAnalysisSubmission
that 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.IOException
Read bytes of lengthchunk
of 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.IOException
Read 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 anAnalysisOutputFile
excel file.- Parameters:
outputFile
-AnalysisOutputFile
The 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
-Row
First row from the excel file.- Returns:
List
ofExcelHeader
header 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
-Workbook
The excel workbook to get sheet names from- Returns:
List
ofString
sheet 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
- TheLong
size of the file in bytes.si
-Boolean
true to use si units- Returns:
- A human readable
String
representation of the file size.
-
isZippedFile
public static boolean isZippedFile(java.nio.file.Path path) throws java.io.IOException
Determine if a file is a zip file.- Parameters:
path
- ThePath
to the file to test.- Returns:
- A boolean indicating whether the file is a zip file.
- Throws:
java.io.IOException
- If an invalidPath
is passed
-
-