@Bean public FileAnalyser fileAnalyser() { return new FileAnalyser(); }
public static String identifyLineDelimiter(File fileToAnalyse) throws IOException { final String fileContent = FileUtils.readFileToString(fileToAnalyse); return identifyLineDelimiter(fileContent); }
public String getMimetype(File inputFile) { try { final MagicMatch match = getMatch(inputFile); final String mimeType = match.getMimeType(); if ("???".equals(mimeType)) { return guessMimeTypeFromDescription(match); } return mimeType; } catch (MagicMatchNotFoundException e) { LOGGER.debug("Failed to get Mime Type", e); final MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap(); return mimeTypesMap.getContentType(inputFile); } }
public String getDescription(File inputFile) { try { return getMatch(inputFile).getDescription(); } catch (MagicMatchNotFoundException e) { throw new IllegalStateException("Unable to detect mimetype of the file", e); } }
/** * Uncompress a .tar file * * @param inputFile input file * @param outputDir output directory * @return list of uncompressed files */ public List<File> uncompress(File inputFile, File outputDir, Consumer<ProgressEntity> onChange) { LOGGER.info( String.format("Uncompressing %s to dir %s.", inputFile.getAbsolutePath(), outputDir.getAbsolutePath())); switch (fileAnalyser.getMimetype(inputFile)) { case "application/x-bzip2": return tar.uncompressTarBz2File(inputFile, outputDir, onChange); case "application/x-gzip": return tar.uncompressTarGzFile(inputFile, outputDir, onChange); case "application/x-xz": return tar.uncompressTarXzFile(inputFile, outputDir, onChange); case "application/zip": case "application/x-dosexec": return zip.uncompressZipFile(inputFile, outputDir, onChange); default: return tar.uncompressTarFile(inputFile, outputDir, onChange); } } }