private void openFile(File file) { // ATM supports only images. if (file.getType().equals("image/png")) { Embedded embedded = new Embedded(file.getName(), file.getResource()); VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); Window w = new Window(file.getName(), layout); layout.addComponent(embedded); layout.setSizeUndefined(); getMainWindow().addWindow(w); } else if (file.getType().equals("text/csv")) { showSpreadsheet(file); } }
public boolean existFile(File file) { boolean res = false; int senderID = this.getProfileID(file.getSender()); int receiverID = this.getProfileID(file.getReceiver()); if (senderID != -1 && receiverID != -1) { try { // creates a SQL Statement object in order to execute the SQL insert command stmt = conn.createStatement(); ResultSet result = stmt.executeQuery( "SELECT * FROM FILES WHERE Size=" + (int) file.length() + " AND Sender=" + senderID + " AND Receiver=" + receiverID + " AND Filename LIKE '" + file.getName() + "%'"); if (result.next()) { res = true; } } catch (SQLException ex) { Logger.getLogger(DataService.class.getName()).log(Level.SEVERE, null, ex); } } return res; }
public String insertFile(File file) throws SQLException { String newName = file.getName() + "_" + (this.getFileLastID() + 1); if (isFriend(file.getSender(), file.getReceiver()) && !existFile(file)) { // Check if the sender and receiver are friends try { // creates a SQL Statement object in order to execute the SQL insert command stmt = conn.createStatement(); stmt.execute( "INSERT INTO Files (Filename, Size, Sender, Receiver, DateUpload, TimeUpload ) " + "VALUES ('" + newName + "', " + (int) file.length() + ", " + getProfileID(file.getSender()) + ", " + getProfileID(file.getReceiver()) + ", '" + file.getDateUpload() + "' , '" + file.getTimeUpload() + "')"); stmt.close(); // System.out.println("Requête executée"); } catch (SQLException e) { // System.err.println(e.toString()); e.toString(); throw e; } return newName; } else { return null; } }
/** * Deletes a <code>File</code> with the given name from the internal <code>File</code> list * Post-condition: <code>File</code> with the passed in filename will be deleted and its <code> * Blocks</code> added back to available <code>Blocks</code> * * @param filename the name of the <code>File</code> * @return successful deletion message * @throws NoSuchFileException if the filename does not match any existing <code>File</code> */ public String delete(String filename) throws NoSuchFileException { Iterator<File> itr = FAT32.iterator(); boolean fileFound = false; // Iterate through list of files to look for filename while (itr.hasNext()) { File file = itr.next(); if (file.getName().equals(filename)) { fileFound = true; // Iterate through file's blocks, adding them back to available blocks for (int i = 0; i < bytesBlocks(file.getBytes()); i++) { freeBlocks.add(file.remove()); } // Remove file itr.remove(); } } // Throw an exception or return appropriate message if (fileFound == false) { throw new NoSuchFileException(filename + " does not exist!"); } else { return filename + " deleted successfully!\n"; } }
public SloccountReport(SloccountReport old, FileFilter filter) { this(); for (File f : old.getFiles()) { if (filter.include(f)) { this.add(f.getName(), f.getLanguage(), f.getModule(), f.getLineCount()); } } }
public void resetBy(File another) { super.resetBy(another); setId(another.getId()); setDir(another.getDir()); setName(another.getName()); setSize(another.getSize()); setProductionId(another.getProductionId()); }
public void setFileDownloaded(File file) { try { // creates a SQL Statement object in order to execute the SQL insert command stmt = conn.createStatement(); stmt.execute( "UPDATE Files SET IsDelivered = true " + " WHERE Filename LIKE '" + file.getName() + "%'"); stmt.close(); } catch (SQLException e) { System.err.println(e.toString()); } }
public String deleteFile(File file) throws SQLException { String r = "File deleted!"; try { // creates a SQL Statement object in order to execute the SQL insert command stmt = conn.createStatement(); stmt.execute("DELETE FROM Files WHERE Filename='" + file.getName() + "'"); stmt.close(); // System.out.println("Requête executée"); } catch (SQLException e) { // System.err.println(e.toString()); r = e.toString(); throw e; } return r; }
/** * Extends a <code>File</code> by the given size in bytes. Pre-condition: size must be greater * than 0 Post-condition: <code>File</code> with the given filename will be extended by passed in * amount of bytes, and additional <code>Blocks</code> will be allocated to it as needed * * @param filename the name of the <code>File</code> * @param size number of bytes to increase the <code>File</code> by * @return successful extension message * @throws InSufficientDiskSpaceException if there are not enough blocks to extend <code>File * </code> * @throws NoSuchFileException if the filename does not match any existing <code>File</code> */ public String extend(String filename, int size) throws InsufficientDiskSpaceException, NoSuchFileException { Iterator<File> findFile = FAT32.iterator(); boolean fileFound = false; // Check if file exists while (findFile.hasNext()) { if (findFile.next().getName().equalsIgnoreCase(filename)) { fileFound = true; } } // Throw exception if it doesn't if (fileFound == false) { throw new NoSuchFileException(filename + " does not exist!"); } // Check there is enough space to extend file if (size > (freeBlocks.size() * blockSize)) { throw new InsufficientDiskSpaceException( "Not enough disk space to extend " + filename + " \n"); } else { Iterator<File> itr = FAT32.iterator(); // Iterate through list of files to find filename while (itr.hasNext()) { File file = itr.next(); if (file.getName().equals(filename)) { // Calculate the extended size and how many blocks need to be added int newSize = file.getBytes() + size; int blocksToAdd = bytesBlocks(newSize) - bytesBlocks(file.getBytes()); // Take blocks from available blocks and add them to the file for (int i = 0; i < blocksToAdd; i++) { file.add(freeBlocks.remove(0)); } file.addBytes(size); } } // Throw exception or return appropriate message if (fileFound == false) { throw new NoSuchFileException(filename + " does not exist!"); } else { return filename + " extended successfully!\n"; } } }
public int getFileID(File file) { int fileID = -1; try { // creates a SQL Statement object in order to execute the SQL insert command stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet result = stmt.executeQuery( "SELECT FileID from FILES WHERE Filename LIKE '" + file.getName() + "%'"); if (result.next()) { // if result of the query is not empty fileID = result.getInt(1); } stmt.close(); } catch (SQLException e) { e.printStackTrace(); } return fileID; }
/** * Truncates a <code>File</code> by the given size in bytes. Pre-condition: size must be greater * than 0 Post-condition: <code>File</code> with the given filename will be truncated by passed in * amount of bytes, and <code>Blocks</code> will be de-allocated to it as needed * * @param filename the name of the <code>File</code> * @param size number of bytes to truncate the <code>File</code> by * @return successful truncation message * @throws NoSuchFileException if the filename does not match any existing <code>File</code> * @throws FileUnderflowException if number of truncating bytes is greater than <code>File</code> * size */ public String truncate(String filename, int size) throws NoSuchFileException, FileUnderflowException { Iterator<File> itr = FAT32.iterator(); boolean fileFound = false; // Iterate through list of files to find filename while (itr.hasNext()) { File file = itr.next(); if (file.getName().equals(filename)) { fileFound = true; // If truncating by total file size, delete the file instead if (file.getBytes() == size) { delete(filename); } else if (file.getBytes() < size) { throw new FileUnderflowException( "Tried to truncate " + filename + " by " + size + " bytes, but it is only " + file.getBytes() + " bytes!\n"); } else { // Calculate the truncated size and how many blocks need to be removed int newSize = file.getBytes() - size; int blocksToRemove = bytesBlocks(file.getBytes()) - bytesBlocks(newSize); // Take blocks from file and add them to available blocks for (int i = 0; i < blocksToRemove; i++) { freeBlocks.add(file.remove()); } file.delBytes(size); } } } // Throw exception or return appropriate message if (fileFound == false) { throw new NoSuchFileException(filename + " does not exist!"); } else { return filename + " truncated successfully!\n"; } }
public static long backupExists(ApplicationInfo in){ PackageInfo i = null; String PATH = Environment.getExternalStorageDirectory().getPath(); try { i = nPManager.getPackageInfo(in.packageName, 0); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } File file = new File(PATH + "/File Quest/AppBackup"); if( file.exists() && new File(PATH + "/File Quest").exists()){ for(File f:file.listFiles()){ String out_file = nPManager.getApplicationLabel(in) + "-v"+i.versionName + ".apk"; if(f.getName().equals(out_file)){ return f.lastModified(); } } } return 0; }
private void showSpreadsheet(File file) { // ApplicationResource resource = (ApplicationResource) // file.getResource(); String string = new String(file.bas.toByteArray()); String[] rows = string.split("\n"); String[] cols = rows[0].split(","); Table table = new Table(); for (String string2 : cols) { // String col = string2.replaceAll("\"", ""); // remove surrounding "" table.addContainerProperty(string2, String.class, ""); } for (int i = 1; i < rows.length; i++) { String[] split = rows[i].split(","); table.addItem(split, "" + i); } VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); Window w = new Window(file.getName(), layout); layout.setSizeUndefined(); table.setEditable(true); layout.addComponent(table); getMainWindow().addWindow(w); }
public FileIcon(final File file) { super(new CssLayout()); l = (CssLayout) getCompositionRoot(); setWidth(null); l.setWidth(null); setDragStartMode(DragStartMode.WRAPPER); // drag all contained // components, not just the // one on it started this.file = file; Resource icon2 = file.getIcon(); String name = file.getName(); l.addComponent(new Embedded(null, icon2)); l.addComponent(new Label(name)); l.addListener( new LayoutClickListener() { @Override @SuppressWarnings("static-access") public void layoutClick(LayoutClickEvent event) { if (event.isDoubleClick()) { if (file instanceof Folder) { get().tree1.setValue(file); } else { String type = file.getType(); if (canDisplay(type)) { DDTest6.get().openFile(file); } } } } String[] knownTypes = new String[] {"image/png", "text/csv"}; private boolean canDisplay(String type) { if (type != null) { for (String t : knownTypes) { if (t.equals(type)) { return true; } } } return false; } }); if (file instanceof Folder) { setDropHandler( new DropHandler() { @Override public AcceptCriterion getAcceptCriterion() { return new Not(SourceIsTarget.get()); } @Override public void drop(DragAndDropEvent dropEvent) { File f = null; if (dropEvent.getTransferable().getSourceComponent() instanceof FileIcon) { FileIcon new_name = (FileIcon) dropEvent.getTransferable().getSourceComponent(); f = new_name.file; } else if (dropEvent.getTransferable().getSourceComponent() == tree1) { f = (File) ((DataBoundTransferable) dropEvent.getTransferable()).getItemId(); } if (f != null) { get().setParent(f, (Folder) FileIcon.this.file); } } }); } }
public void visit(File file) { // ファイルを訪問したときに呼ばれる if (file.getName().endsWith(filetype)) { found.add(file); } }