public static void copyDir( @NotNull File fromDir, @NotNull File toDir, @Nullable final FileFilter filter) throws IOException { ensureExists(toDir); if (isAncestor(fromDir, toDir, true)) { LOG.error(fromDir.getAbsolutePath() + " is ancestor of " + toDir + ". Can't copy to itself."); return; } File[] files = fromDir.listFiles(); if (files == null) throw new IOException( CommonBundle.message("exception.directory.is.invalid", fromDir.getPath())); if (!fromDir.canRead()) throw new IOException( CommonBundle.message("exception.directory.is.not.readable", fromDir.getPath())); for (File file : files) { if (filter != null && !filter.accept(file)) { continue; } if (file.isDirectory()) { copyDir(file, new File(toDir, file.getName()), filter); } else { copy(file, new File(toDir, file.getName())); } } }
/** * Recursive function to enumerate classes inside a classpath folder * * @param superClass * @param classloader * @param classes * @param packagePath * @param packageName */ private static void enumerateDirectory( String prefix, Class superClass, ClassLoader classloader, LinkedList<Class> classes, File packagePath, String packageName) { File[] classFiles = packagePath.listFiles(); for (File classFile : classFiles) { if (classFile.isDirectory()) { enumerateDirectory( prefix, superClass, classloader, classes, classFile, packageName + classFile.getName() + "."); } else { if (classFile.getName().endsWith(".class") && (prefix == null || classFile.getName().startsWith(prefix))) { String classFileName = classFile.getName(); String className = packageName + classFileName.substring(0, classFileName.length() - 6); checkAndAddClass(classloader, superClass, classes, className); } } } }
private static void index_h(String prefix, File file, IndexWriter indexWriter) throws IOException { Document doc = null; if (file.isDirectory()) { File files[] = file.listFiles(); for (File file1 : files) { index_h(prefix + FILE_SEPARATOR + file.getName(), file1, indexWriter); } } else { String content = FileUtils.readFileToString(file, "utf-8"); System.out.println("=============================================================="); System.out.println("index_h " + content); System.out.println("=============================================================="); String filename = prefix + FILE_SEPARATOR + file.getName(); String path = file.getAbsolutePath(); doc = new Document(); doc.add(new Field("content", content, Field.Store.YES, Field.Index.ANALYZED)); doc.add(new Field("relative_path", filename, Field.Store.YES, Field.Index.NOT_ANALYZED)); indexWriter.addDocument(doc); } }
public static void createAd(@Valid Ad ad, File photo) throws IOException { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // get current date time with Date() Date date = new Date(); ad.createDate = dateFormat.format(date); ad.student = Student.findById(1l); // ad.category=Category.findById(ad.category.id); File d = new File(Play.applicationPath.getAbsolutePath() + "/public/img/ads"); // if(d.exists()){ String suffix = FilenameUtils.getExtension(photo.getName()); File o = File.createTempFile("ad-", "." + suffix, d); InputStream input = new FileInputStream(photo); OutputStream output = new FileOutputStream(o); ad.image = o.getName(); ad.save(); try { IOUtils.copy(input, output); } finally { IOUtils.closeQuietly(output); IOUtils.closeQuietly(input); } Ads.index(1, ad.category.id.toString()); }
private void copyAllFilesToLogDir(File node, File parent) throws IOException { if (!node.getAbsoluteFile().equals(parent.getAbsoluteFile()) && node.isFile() && !node.getParentFile().equals(parent)) { String fileNamePrefix = node.getName().substring(0, node.getName().lastIndexOf('.')); String fileNameSuffix = node.getName().substring(node.getName().lastIndexOf('.')); String newFilePath = node.getParentFile().getAbsolutePath() + File.separator + fileNamePrefix.replace(".", "_") + fileNameSuffix; File newNode = new File(newFilePath); if (node.renameTo(newNode)) { FileUtils.copyFileToDirectory(newNode, parent); } } if (node.isDirectory()) { String[] subNote = node.list(); for (String filename : subNote) { copyAllFilesToLogDir(new File(node, filename), parent); } if (!node.equals(parent)) { FileUtils.deleteDirectory(node); } } }
public static String[] listFiles(File dir, Boolean includeSubDirs) throws IOException { FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); } }; File[] subFolders = dir.listFiles(fileFilter); List<String> files = new ArrayList<String>(); List<File> fileArray = new ArrayList<File>( FileUtils.listFiles( dir, TrueFileFilter.INSTANCE, includeSubDirs ? TrueFileFilter.INSTANCE : null)); for (File file : fileArray) { if (file.isFile()) { if (includeSubDirs && containsParentFolder(file, subFolders)) { files.add(file.getParentFile().getName() + File.separator + file.getName()); } else { files.add(file.getName()); } } } return (String[]) files.toArray(new String[0]); }
private void updateData(MavenProgressIndicator progress, File newDataDir, boolean fullUpdate) throws MavenIndexException { IndexData newData = new IndexData(newDataDir); try { doUpdateIndexData(newData, progress); newData.flush(); } catch (Throwable e) { newData.close(true); FileUtil.delete(newDataDir); if (e instanceof MavenServerIndexerException) throw new MavenIndexException(e); if (e instanceof IOException) throw new MavenIndexException(e); throw new RuntimeException(e); } synchronized (this) { IndexData oldData = myData; myData = newData; myDataDirName = newDataDir.getName(); if (fullUpdate) { myUpdateTimestamp = System.currentTimeMillis(); } oldData.close(true); for (File each : FileUtil.notNullize(myDir.listFiles())) { if (each.getName().startsWith(DATA_DIR_PREFIX) && !each.getName().equals(myDataDirName)) { FileUtil.delete(each); } } } }
private String getTitle(File f) { String result = ""; if (!f.getName().endsWith(".html")) return "not HTML"; else { try { BufferedReader reader = new BufferedReader(new FileReader(f)); String ligne = reader.readLine(); while (ligne != null && !ligne.contains("<TITLE>") && !ligne.contains("<title>")) { ligne = reader.readLine(); } reader.close(); if (ligne == null) return "No TITLE in page " + f.getName(); else { String fin = ""; String debut = ""; if (ligne.contains("</TITLE>")) { debut = "<TITLE>"; fin = "</TITLE>"; } else if (ligne.contains("</title>")) { debut = "<title>"; fin = "</title>"; } else return "No title in page " + f.getName(); int fin_index = ligne.lastIndexOf(fin); result = ligne.substring(ligne.indexOf(debut) + 7, fin_index); return result; } } catch (Exception e) { LOG.error("Error while reading file " + e); return "Error for file " + f.getName(); } } }
public void saveCache( JMXInstrumentedCache<K, V> cache, File savedCachePath, Function<K, byte[]> converter) throws IOException { long start = System.currentTimeMillis(); String msgSuffix = " " + savedCachePath.getName() + " for " + cfname + " of " + ksname; logger.debug("saving" + msgSuffix); int count = 0; File tmpFile = File.createTempFile(savedCachePath.getName(), null, savedCachePath.getParentFile()); FileOutputStream fout = new FileOutputStream(tmpFile); ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(fout)); FileDescriptor fd = fout.getFD(); for (K key : cache.getKeySet()) { byte[] bytes = converter.apply(key); out.writeInt(bytes.length); out.write(bytes); ++count; } out.flush(); fd.sync(); out.close(); if (!tmpFile.renameTo(savedCachePath)) throw new IOException("Unable to rename cache to " + savedCachePath); if (logger.isDebugEnabled()) logger.debug( "saved " + count + " keys in " + (System.currentTimeMillis() - start) + " ms from" + msgSuffix); }
synchronized void migrateData(DataStore targetStore) { ForceLoadAllClaims(this); targetStore.ClearInventoryOnJoinPlayers = ClearInventoryOnJoinPlayers; // migrate claims for (Claim c : this.claims) { GriefPrevention.AddLogEntry("Migrating Claim #" + c.getID()); targetStore.addClaim(c); } // migrate groups Iterator<String> groupNamesEnumerator = this.permissionToBonusBlocksMap.keySet().iterator(); while (groupNamesEnumerator.hasNext()) { String groupName = groupNamesEnumerator.next(); targetStore.saveGroupBonusBlocks(groupName, this.permissionToBonusBlocksMap.get(groupName)); } // migrate players for (PlayerData pdata : getAllPlayerData()) { targetStore.playerNameToPlayerDataMap.put(pdata.playerName, pdata); targetStore.savePlayerData(pdata.playerName, pdata); } // migrate next claim ID if (this.nextClaimID > targetStore.nextClaimID) { targetStore.setNextClaimID(this.nextClaimID); } // rename player and claim data folders so the migration won't run again int i = 0; File claimsBackupFolder; File playersBackupFolder; do { String claimsFolderBackupPath = claimDataFolderPath; if (i > 0) claimsFolderBackupPath += String.valueOf(i); claimsBackupFolder = new File(claimsFolderBackupPath); String playersFolderBackupPath = playerDataFolderPath; if (i > 0) playersFolderBackupPath += String.valueOf(i); playersBackupFolder = new File(playersFolderBackupPath); i++; } while (claimsBackupFolder.exists() || playersBackupFolder.exists()); File claimsFolder = new File(claimDataFolderPath); File playersFolder = new File(playerDataFolderPath); claimsFolder.renameTo(claimsBackupFolder); playersFolder.renameTo(playersBackupFolder); GriefPrevention.AddLogEntry( "Backed your file system data up to " + claimsBackupFolder.getName() + " and " + playersBackupFolder.getName() + "."); GriefPrevention.AddLogEntry( "If your migration encountered any problems, you can restore those data with a quick copy/paste."); GriefPrevention.AddLogEntry( "When you're satisfied that all your data have been safely migrated, consider deleting those folders."); }
/** * Gets a list of <code>IIOImage</code> objects for an image file. * * @param imageFile input image file. It can be any of the supported formats, including TIFF, * JPEG, GIF, PNG, BMP, JPEG, and PDF if GPL Ghostscript is installed * @return a list of <code>IIOImage</code> objects * @throws Exception */ public static List<IIOImage> getIIOImageList(File imageFile) throws IOException { File workingTiffFile = null; ImageReader reader = null; ImageInputStream iis = null; try { // convert PDF to TIFF if (imageFile.getName().toLowerCase().endsWith(".pdf")) { workingTiffFile = PdfUtilities.convertPdf2Tiff(imageFile); imageFile = workingTiffFile; } List<IIOImage> iioImageList = new ArrayList<IIOImage>(); String imageFileName = imageFile.getName(); String imageFormat = imageFileName.substring(imageFileName.lastIndexOf('.') + 1); if (imageFormat.matches("(pbm|pgm|ppm)")) { imageFormat = "pnm"; } else if (imageFormat.equals("jp2")) { imageFormat = "jpeg2000"; } Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(imageFormat); reader = readers.next(); if (reader == null) { throw new RuntimeException( "Need to install JAI Image I/O package.\nhttps://jai-imageio.dev.java.net"); } iis = ImageIO.createImageInputStream(imageFile); reader.setInput(iis); int imageTotal = reader.getNumImages(true); for (int i = 0; i < imageTotal; i++) { // IIOImage oimage = new IIOImage(reader.read(i), null, // reader.getImageMetadata(i)); IIOImage oimage = reader.readAll(i, reader.getDefaultReadParam()); iioImageList.add(oimage); } return iioImageList; } finally { try { if (iis != null) { iis.close(); } if (reader != null) { reader.dispose(); } } catch (Exception e) { // ignore } if (workingTiffFile != null && workingTiffFile.exists()) { workingTiffFile.delete(); } } }
private String getPlayerDataFile(String sPlayerName) { String retval = null; try { String strPath = playerDataFolderPath + File.separator; String scaseSensitive = strPath + sPlayerName; String scaseInsensitive = strPath + sPlayerName.toLowerCase(); File examinepath = new File(strPath); File CaseSensitive = null; File CaseInsensitive = null; // search for file. for (File iterate : examinepath.listFiles()) { // if it equals the name case-sensitively, if (iterate.getName().equals(sPlayerName)) { // assign our case sensitive name CaseSensitive = iterate; } else if (iterate.getName().equalsIgnoreCase(sPlayerName) && iterate.getName().toLowerCase().equals(iterate.getName())) { // otherwise assign our case insensitive name. CaseInsensitive = iterate; scaseInsensitive = CaseInsensitive.getName(); } } if (CaseSensitive != null && CaseInsensitive != null && !scaseInsensitive.equals(scaseSensitive)) { try { // delete caseinsensitive file... new File(scaseInsensitive).delete(); // copy case sensitive version in it's place. copyFile(CaseSensitive, CaseInsensitive); // CaseInsensitive.renameTo(new File(scaseInsensitive + "-backup")); // delete the case sensitive file. CaseSensitive.delete(); } catch (IOException iox) { // ignore } } return retval = scaseInsensitive; } finally { Debugger.Write( "Flat: Player Data retrieved for " + sPlayerName + ":" + retval, Debugger.DebugLevel.Verbose); } }
private void visit(Set<String> names, String prefix, File file) { for (File child : file.listFiles()) { if (child.isFile()) { names.add(prefix + child.getName()); } else if (child.isDirectory()) { visit(names, prefix + child.getName() + "/", child); } } }
/** * @param guid * @throws IOException */ public void delete(int guid) throws IOException { // delete file File file = new File(Integer.toString(guid)); if (file.delete()) { System.out.println(file.getName() + " deleted"); } else { System.out.println("Failed to delete " + file.getName()); } }
private void analyze(File f) throws IOException { String[] list = f.list(); if (list != null) { for (int i = 0; i < list.length; i++) analyze(new File(f.getCanonicalPath() + "\\" + list[i])); } else { if (f.getName().endsWith(".ma") || f.getName().endsWith(".fg")) count(f); } }
private void runFromDir(File folder) throws IOException { System.out.println( "LongevityRecordedTests.testAllInFolder running longjevity test from data in folder " + folder); if (folder.getName().indexOf("_") < 0) return; String branchName = folder.getName().substring(0, folder.getName().indexOf("_")); run(folder.getCanonicalPath(), branchName); printStats(branchName); }
/** * Crea el fichero de indices con la informacion inicial necesaria para un archivo concreto. * * @param fichero es el fichero de indices que tendra toda la informacion. * @param archivo es el objeto que representa el archivo en concreto. * @param fragmentos es la lista de fragmentos que faltan de dicho archivo. */ public void crearFicheroIndices(File fichero, Archivo archivo, Vector<Fragmento> fragmentos) { Vector<Fragmento> fragTengo = new Vector<Fragmento>(), fragFaltan = fragmentos; Indices indices = new Indices(archivo, fragTengo, fragFaltan); ByteArrayOutputStream bs = new ByteArrayOutputStream(); try { ObjectOutputStream os = new ObjectOutputStream(bs); os.writeObject(indices); os.close(); } catch (IOException e) { /*System.out.println("Error -> posibles causas: "); System.out.println( "\tProblemas al crear un flujo de bytes serializable" ); System.out.println( "\tProblemas al serializar el objeto indice" ); System.out.println( "\tProblemas al cerrar el flujo serializable" );*/ ControlDeErrores.getInstancia() .registrarError( ErrorEGorilla.ERROR_DISCO, "Error -> posibles causas: " + "\tProblemas al crear un flujo de bytes serializable" + "\tProblemas al serializar el objeto indice" + "\tProblemas al cerrar el flujo serializable"); // e.printStackTrace(); } byte[] bytes = bs.toByteArray(); // devuelve byte[] try { if (fichero.exists() == true) { String nombreNuevoFichero = fichero.getName(); nombreNuevoFichero += "_" + archivo.getHash(); fichero = new File(nombreNuevoFichero); } FileOutputStream ficheroIndices = new FileOutputStream(fichero); BufferedOutputStream bufferedOutput = new BufferedOutputStream(ficheroIndices); bufferedOutput.write(bytes, 0, bytes.length); bufferedOutput.close(); // creo que tambien hace falta cerrar el otro ficheroIndices.close(); } catch (FileNotFoundException e) { System.out.println("No existe el fichero <" + fichero.getName() + ">"); } catch (IOException e) { /*System.out.println("Error -> posibles causas: "); System.out.println( "\tProblemas al escribir en el fichero <"+fichero.getName()+">" ); System.out.println( "\tProblemas al cerrar el flujo o el fichero <"+fichero.getName()+">" );*/ ControlDeErrores.getInstancia() .registrarError( ErrorEGorilla.ERROR_DISCO, "Error -> posibles causas: " + "\tProblemas al escribir en el fichero <" + fichero.getName() + ">" + "\tProblemas al cerrar el flujo o el fichero <" + fichero.getName() + ">"); // e.printStackTrace(); } }
public static String stripExtension(File file) { try { int i = file.getName().lastIndexOf("."); String s = file.getName().substring(0, i); return s; } catch (Exception ex) { return null; } }
// http://stackoverflow.com/questions/3154488/best-way-to-iterate-through-a-directory-in-java public void showFiles(File[] files) { for (File file : files) { if (file.isDirectory()) { System.out.println("Directory: " + file.getName()); showFiles(file.listFiles()); // Calls same method again. } else { System.out.println("File: " + file.getName()); } } }
protected long getTotalFileSizeSupport(File file) throws TOTorrentException { String name = file.getName(); ///////////////////////////////////////// ///////////////////////////////////// if (name.equals(".") || name.equals("..")) { return (0); } if (!file.exists()) { throw (new TOTorrentException( "TOTorrentCreate: file '" + file.getName() + "' doesn't exist", TOTorrentException.RT_FILE_NOT_FOUND)); } if (file.isFile()) { if (!ignoreFile(name)) { total_file_count++; return (file.length()); } else { return (0); } } else { File[] dir_files = file.listFiles(); if (dir_files == null) { throw (new TOTorrentException( "TOTorrentCreate: directory '" + file.getAbsolutePath() + "' returned error when listing files in it", TOTorrentException.RT_FILE_NOT_FOUND)); } long length = 0; for (int i = 0; i < dir_files.length; i++) { length += getTotalFileSizeSupport(dir_files[i]); } return (length); } }
/** * Perform recovery on commit logs located in the directory specified by the config file. * * @return the number of mutations replayed */ public int recover() throws IOException { // If createReserveSegments is already flipped, the CLSM is running and recovery has already // taken place. if (allocator.createReserveSegments) return 0; // Allocator could be in the process of initial startup with 0 active and available segments. We // need to wait for // the allocation manager to finish allocation and add it to available segments so we don't get // an invalid response // on allocator.manages(...) below by grabbing a file off the filesystem before it's added to // the CLQ. allocator.allocatingFrom(); FilenameFilter unmanagedFilesFilter = new FilenameFilter() { public boolean accept(File dir, String name) { // we used to try to avoid instantiating commitlog (thus creating an empty segment ready // for writes) // until after recover was finished. this turns out to be fragile; it is less // error-prone to go // ahead and allow writes before recover(), and just skip active segments when we do. return CommitLogDescriptor.isValid(name) && !allocator.manages(name); } }; // submit all existing files in the commit log dir for archiving prior to recovery - // CASSANDRA-6904 for (File file : new File(DatabaseDescriptor.getCommitLogLocation()).listFiles(unmanagedFilesFilter)) { archiver.maybeArchive(file.getPath(), file.getName()); archiver.maybeWaitForArchiving(file.getName()); } assert archiver.archivePending.isEmpty() : "Not all commit log archive tasks were completed before restore"; archiver.maybeRestoreArchive(); File[] files = new File(DatabaseDescriptor.getCommitLogLocation()).listFiles(unmanagedFilesFilter); int replayed = 0; if (files.length == 0) { logger.info("No commitlog files found; skipping replay"); } else { Arrays.sort(files, new CommitLogSegmentFileComparator()); logger.info("Replaying {}", StringUtils.join(files, ", ")); replayed = recover(files); logger.info("Log replay complete, {} replayed mutations", replayed); for (File f : files) allocator.recycleSegment(f); } allocator.enableReserveSegmentCreation(); return replayed; }
public boolean edtImport(File fi, String date, String tags) { if (!fi.exists()) { System.err.println("import: file " + fi.getAbsolutePath() + " doesnt exist"); return false; } String pname = fi.getName(); if (store.containsEntry(pname)) { System.err.println("import: already have a file named " + pname); return false; } long size = fi.length() / KILOBYTE; File save = sec.encryptMainFile(fi, storeLocs.get(0), true); if (save == null) { System.err.println("import: Encryption failure"); return false; } if (checkImports) { boolean success = true; File checkfi = new File(idx + ".check"); File checkOut = sec.encryptSpecialFile(save, checkfi, false); if (checkOut == null) success = false; else { String fiHash = sec.digest(fi); String outHash = sec.digest(checkOut); if (fiHash == null || outHash == null || fiHash.length() < 1 || !fiHash.equals(outHash)) success = false; } checkfi.delete(); if (!success) { save.delete(); if (JOptionPane.showConfirmDialog( frm, "Confirming " + fi.getName() + "failed\n\n - Would you like to re-import the file?", "Import failed", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { String j = impJob(fi, date, tags); synchronized (jobs) { if (priorityExport) jobs.addLast(j); else jobs.addFirst(j); } } return false; } } if (!fi.delete()) { System.err.println("import: Couldnt delete old file - continuing"); } store.add(save.getName(), pname, date, size, tags, 0); needsSave = true; return true; }
public static void main(String[] args) { BackgroundEstimation estimation = new BolstadEMBackgroundEstimation(); // BackgroundEstimation estimation = new UniformBackgroundEstimation(); String key = args[0]; WorkflowProperties props = new WorkflowProperties(); File fplus = new File(props.getDirectory(), String.format("%s_plus.raw", key)); File fminus = new File(props.getDirectory(), String.format("%s_negative.raw", key)); // LogTransform transform = LogTransform.NONE; LogTransform transform = LogTransform.LOG_TO_EXP; BackgroundRemoval norm = new BackgroundRemoval(estimation, transform); try { System.out.println(String.format("Loading: %s", fplus.getName())); norm.load(new WorkflowDataLoader(fplus)); System.out.println(String.format("Loading: %s", fminus.getName())); norm.load(new WorkflowDataLoader(fminus)); WorkflowIndexing indexing = props.getIndexing(key); System.out.println(String.format("Removing background...")); norm.removeBackground(); Filter<ProbeLine, ProbeLine> plus = new Filter<ProbeLine, ProbeLine>() { public ProbeLine execute(ProbeLine p) { return p.strand.equals("+") ? p : null; } }; Filter<ProbeLine, ProbeLine> minus = new Filter<ProbeLine, ProbeLine>() { public ProbeLine execute(ProbeLine p) { return p.strand.equals("-") ? p : null; } }; System.out.println(String.format("Outputting background-removed results...")); File plusOut = new File(props.getDirectory(), String.format("%s_plus.corrected", key)); File minusOut = new File(props.getDirectory(), String.format("%s_negative.corrected", key)); outputProbes(new FilterIterator<ProbeLine, ProbeLine>(plus, norm.iterator()), plusOut); System.out.println(String.format("\t%s", plusOut.getAbsolutePath())); outputProbes(new FilterIterator<ProbeLine, ProbeLine>(minus, norm.iterator()), minusOut); System.out.println(String.format("\t%s", minusOut.getAbsolutePath())); } catch (IOException e) { e.printStackTrace(); } }
/** * public char[] jetPass(){ JPasswordField psf = new JPasswordField(); psf.grabFocus(); int opt = * JOptionPane.showConfirmDialog(frm, psf, "Password", JOptionPane.PLAIN_MESSAGE); if(opt == * JOptionPane.OK_OPTION) return psf.getPassword(); return null; } * * <p>public String jetString(String msg, String ttl){ return JOptionPane.showInputDialog(frm, * msg, ttl, JOptionPane.QUESTION_MESSAGE); }* */ public static String jobString(String job) { if (job.charAt(0) == IMPORT_FLAG) { String[] brk = job.split(",", 4); // 4 parts to an import string File inf = new File(brk[1]); return "import " + inf.getName(); } else { String[] brk = job.split(",", 3); // 3 parts to export string File plf = new File(brk[2]); return "export " + plf.getName(); } }
public void postProcessCmdLineArgs(CmdLineParser cmdLineParser) throws CmdLineException { for (File inputFile : inputFiles) { if (inputFile.getName().endsWith(".xml") || inputFile.getName().endsWith(".vtt") || inputFile.getName().endsWith(".dfxp")) { throw new CmdLineException( cmdLineParser, new AbstractEncryptOrNotCommand.Message( "Subtitle files must either be supplied via command line option --subtitles or --closed-captions")); } } }
public static void upload(File[] files) throws FileNotFoundException { Files f = null; for (File file : files) { f = new Files(); f.name = file.getName(); f.path = ""; f.image = new Blob(); f.image.set(new FileInputStream(file), MimeTypes.getContentType(file.getName())); f.save(); renderText(f.id); } }
public void save(File file) throws IOException { if (file.getName().endsWith(".gif")) { ImageIO.write(_i, "png", file); } else if (file.getName().endsWith(".jpg")) { ImageIO.write(_i, "jpg", file); } else { if (!file.getName().endsWith(".png")) { file = new File(file.toString() + ".png"); } ImageIO.write(_i, "png", file); } }
/** Find the corresponding meta data file from a given block file */ private static long parseGenerationStamp(File blockFile, File metaFile) throws IOException { String metaname = metaFile.getName(); String gs = metaname.substring( blockFile.getName().length() + 1, metaname.length() - METADATA_EXTENSION.length()); try { return Long.parseLong(gs); } catch (NumberFormatException nfe) { throw (IOException) new IOException("blockFile=" + blockFile + ", metaFile=" + metaFile).initCause(nfe); } }
/** * @param verificationMapFromUnpackedFiles Map of BBI files names to their corresponding * verifications * @param listOfBBIfiles List with BBI files extracted from the archive * @return List of DTOs containing BBI filename, verification id, outcome of parsing (true/false), * and reason of rejection (if the bbi file was rejected) */ private List<BBIOutcomeDTO> processListOfBBIFiles( Map<String, Map<String, String>> verificationMapFromUnpackedFiles, List<File> listOfBBIfiles, User calibratorEmployee) throws ParseException { List<BBIOutcomeDTO> resultsOfBBIProcessing = new ArrayList<>(); for (File bbiFile : listOfBBIfiles) { Map<String, String> correspondingVerificationMap = verificationMapFromUnpackedFiles.get(bbiFile.getName()); String correspondingVerification = correspondingVerificationMap.get(Constants.VERIFICATION_ID); BBIOutcomeDTO.ReasonOfRejection reasonOfRejection = null; if (correspondingVerification == null) { try { correspondingVerification = createNewVerificationFromMap(correspondingVerificationMap, calibratorEmployee); parseAndSaveBBIFile(bbiFile, correspondingVerification, bbiFile.getName()); Verification verification = verificationService.findById(correspondingVerification); verification.setStatus(Status.CREATED_BY_CALIBRATOR); verificationService.saveVerification(verification); } catch (NoSuchElementException e) { reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.INVALID_COUNTER_SIZE_AND_SYMBOL; logger.info(e); } catch (Exception e) { reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.BBI_IS_NOT_VALID; logger.info(e); } } else { try { updateVerificationFromMap(correspondingVerificationMap, correspondingVerification); parseAndSaveBBIFile(bbiFile, correspondingVerification, bbiFile.getName()); } catch (NoSuchElementException e) { reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.INVALID_COUNTER_SIZE_AND_SYMBOL; logger.info(e); } catch (IOException e) { reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.BBI_IS_NOT_VALID; logger.info(e); } catch (Exception e) { reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.INVALID_VERIFICATION_CODE; logger.info(e); } } if (reasonOfRejection == null) { resultsOfBBIProcessing.add( BBIOutcomeDTO.accept(bbiFile.getName(), correspondingVerification)); } else { resultsOfBBIProcessing.add( BBIOutcomeDTO.reject(bbiFile.getName(), correspondingVerification, reasonOfRejection)); } } return resultsOfBBIProcessing; }
private void deleteListImpl(final ShelvedChangeList changeList) { File file = new File(changeList.PATH); myFileProcessor.delete(file.getName()); for (ShelvedBinaryFile binaryFile : changeList.getBinaryFiles()) { final String path = binaryFile.SHELVED_PATH; if (path != null) { File binFile = new File(path); myFileProcessor.delete(binFile.getName()); } } }