List of usage examples for java.io FileOutputStream flush
public void flush() throws IOException
From source file:app.logica.gestores.GestorEmail.java
/** * Mtodo para el envo de email usando la API de Gmail * /* w ww .ja v a 2 s .co m*/ * @param destinatario * destinatario del email * @param asunto * asunto del email * @param mensaje * cuerpo del mensaje del email * @param archivo * arhivo que ser adjuntado al email * @throws IOException * @throws MessagingException */ public void enviarEmail(String destinatario, String asunto, String mensaje, Archivo archivo) throws IOException, MessagingException { // Build a new authorized API client service. //Se obtiene un servicio de cliente de la API //Adems se solicitan los permisos necesarios al usuario Gmail service = getGmailService(); //La palabra clave "me" representa al dueo de la cuenta con la que se enviar el email String user = "me"; //Se crea un archivo temporal para poder enviarlo como adjunto File archivoTMP = new File(URL_RESERVA); FileOutputStream fos = new FileOutputStream(archivoTMP); fos.write(archivo.getArchivo()); fos.flush(); fos.close(); //Se invoca al mtodo de la API con los parmetros necesarios, se pasa la direccin de email de la inmobiliaria como campo "from" sendMessage(service, user, createEmailWithAttachment(destinatario, "olimpoagilinmobiliaria2016@gmail.com", asunto, mensaje, archivoTMP)); //Finalmente se borra el archivo temporal archivoTMP.delete(); }
From source file:MainWindow.java
public MainWindow() { // Login Routine loginDialog = new LoginDialog(); // loginDialog.nameField.setText("cornelius.preidel@googlemail.com"); // loginDialog.passwordField.setText("germany"); loginDialog.setSize(400, 150);//from ww w .j av a2s .c o m loginDialog.setModal(true); loginDialog.setLocationRelativeTo(null); loginDialog.setVisible(true); // Get the connected ApiCore core = loginDialog._core; // Init the UI mainFrame = new JFrame("MainApplication"); mainFrame.setSize(500, 500); mainFrame.setLocationRelativeTo(null); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setLayout(new GridLayout(5, 1)); // WebProjectsList webprojectlist = new WebProjectsList(core); // mainFrame.add(webprojectlist); // Create the APIS Teams teamsAPI = new Teams(core); final Projects projectsAPI = new Projects(core); final Divisions divisionsAPI = new Divisions(core); final Attachments attachmentAPI = new Attachments(core); final Issues issueAPI = new Issues(core); // TEAMS List TeamsList teamList = new TeamsList(); teamList.setTeams(teamsAPI.GetTeams()); mainFrame.add(teamList); // PROJECTS List projectsList = new ProjectsList(); mainFrame.add(projectsList); // DIVISIONS List divisionsList = new DivisionsList(); // mainFrame.add(divisionsList); // DIVISIONS Table divisionsTable = new DivisionsTable(core); mainFrame.add(divisionsTable); // Attachments attachmentsList = new AttachmentsList(); mainFrame.add(attachmentsList); // Attachments issuesList = new IssuesList(); mainFrame.add(issuesList); PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { String property = propertyChangeEvent.getPropertyName(); if ("selectedTeam".equals(property)) { DtoTeam selectedTeam = (DtoTeam) propertyChangeEvent.getNewValue(); // Set the global slug core.currentTeam = selectedTeam; projectsList.setProjects(projectsAPI.GetProjects()); } else if ("selectedProject".equals(property)) { DtoProject selectedProject = (DtoProject) propertyChangeEvent.getNewValue(); // Divisions divisionsList.setDivisions(divisionsAPI.GetDivisions(selectedProject.GetId())); divisionsTable.setDivisions(divisionsAPI.GetDivisions(selectedProject.GetId())); // Attachments attachmentsList.setAttachments(attachmentAPI.GetAttachments(selectedProject.GetId())); // Issues issuesList.setIssues(issueAPI.GetIssues(selectedProject.GetId())); } else if ("selectedDivision".equals(property)) { DtoDivision selectedDivision = (DtoDivision) propertyChangeEvent.getNewValue(); // What to do with the division? } else if ("selectedIssue".equals(property)) { DtoIssue selectedDivision = (DtoIssue) propertyChangeEvent.getNewValue(); // What to do with the division? } else { if ("selectedAttachment".equals(property)) { DtoAttachment selectedAttachment = (DtoAttachment) propertyChangeEvent.getNewValue(); InputStream stream = attachmentAPI.DownloadAttachment(selectedAttachment.GetId()); try { byte[] bytes = IOUtils.toByteArray(stream); JFileChooser chooser = new JFileChooser(); int returnVal = chooser.showSaveDialog(chooser); File file = chooser.getSelectedFile(); FileOutputStream fos = new FileOutputStream(file); fos.write(bytes); fos.flush(); fos.close(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } } } }; // Add Listener teamList.addPropertyChangeListener(propertyChangeListener); projectsList.addPropertyChangeListener(propertyChangeListener); divisionsList.addPropertyChangeListener(propertyChangeListener); divisionsTable.addPropertyChangeListener(propertyChangeListener); attachmentsList.addPropertyChangeListener(propertyChangeListener); issuesList.addPropertyChangeListener(propertyChangeListener); }
From source file:com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJobFileSavingImpl.java
private void copy(byte[] data, FileOutputStream os) throws IOException { os.write(data);/* w w w. j a v a 2 s. c o m*/ os.flush(); os.close(); }
From source file:OverwriteProperties.java
/** * Description of the Method/*from www. j a v a 2 s . c o m*/ * * @param flags Description of the Parameter * @exception FileNotFoundException Description of the Exception * @exception IOException Description of the Exception */ public void writeToFile(boolean[] flags) throws FileNotFoundException, IOException { FileOutputStream writer = new FileOutputStream(baseProperties); writer.flush(); for (int i = 0; i < baseArray.size(); i++) { if (true == flags[i]) { if (verbose) { System.out.println("Skipping property[" + i + "] = " + baseArray.get(i)); } continue; } if (verbose) { System.out.println("Writing property[" + i + "] = " + baseArray.get(i)); } writer.write(((String) baseArray.get(i)).getBytes()); writer.write(lineSeparator.getBytes()); writer.flush(); } writer.close(); }
From source file:br.com.ifpb.bdnc.projeto.geo.system.MultipartData.java
public boolean saveImage(String path, FileItemStream item, String nameToSave) { try {//from www .jav a2 s .co m File f = new File(path + File.separator + folder); File parent = new File(f.getParent()); if (!parent.exists()) parent.mkdir(); if (!f.exists()) f.mkdir(); System.out.println(f.getAbsolutePath()); File savedFile = new File(f.getAbsoluteFile() + File.separator + nameToSave); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); return true; } catch (Exception ex) { ex.printStackTrace(); } return false; }
From source file:com.msopentech.thali.utilities.android.AndroidXmlHttpRequestTestActivity.java
/** * Reads in the resource with the specified resourcePath and then creates a file * with the same path in the application's local storage * @param resourcePath// w ww . ja v a 2 s .co m */ private void readResourceIntoDirectory(String resourcePath) { File resourceFile = new File(getFilesDir(), resourcePath); InputStream resourceInputStream = getClass().getResourceAsStream(resourcePath); FileOutputStream resourceFileOutputStream = null; try { resourceFileOutputStream = new FileOutputStream(resourceFile); IOUtils.copy(resourceInputStream, resourceFileOutputStream); resourceFileOutputStream.flush(); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { try { if (resourceInputStream != null) { resourceInputStream.close(); } if (resourceFileOutputStream != null) { resourceFileOutputStream.close(); } } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:com.twinflag.coofiletouch.AuthorityUtil.java
public void updateAuthorityFileContent(String content) { if (DeviceUtil.isSdCardExist() && content != null) { boolean createAuthFileSuccesss = false; File storageDir = null;// www . ja v a2s. c om File authorityFile = null; String authorityFilePath = null; String lincenseFileFullName = null; String lincenseFileName = null; storageDir = Environment.getExternalStorageDirectory(); lincenseFileName = DeviceUtil.getDeviceInfo() + ".license"; // lincenseFileName = "6523-8769-2234-85746873.license"; lincenseFileFullName = storageDir.getPath() + File.separator + "twinflag" + File.separator + lincenseFileName; authorityFilePath = storageDir.getPath() + File.separator + "twinflag"; authorityFile = new File(authorityFilePath); if (!authorityFile.exists()) { authorityFile.mkdir(); } File authFile = new File(lincenseFileFullName); if (authFile.exists()) { authFile.delete(); } authFile = new File(lincenseFileFullName); if (!authFile.exists()) { try { authFile.createNewFile(); createAuthFileSuccesss = true; } catch (IOException e) { e.printStackTrace(); } } else { createAuthFileSuccesss = true; } if (createAuthFileSuccesss) { try { byte[] bytes = content.getBytes(); FileOutputStream fileOutputStream = new FileOutputStream(authFile); fileOutputStream.write(bytes); fileOutputStream.flush(); fileOutputStream.close(); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:it.eng.spagobi.engines.exporters.KpiExporter.java
public File getKpiExportXML(List<KpiResourceBlock> kpiBlocks, BIObject obj, String userId) throws Exception { File tmpFile = null;/*w ww. ja v a2 s . c om*/ logger.debug("IN"); try { // recover BiObject Name Object idObject = obj.getId(); if (idObject == null) { logger.error("Document id not found"); } Integer id = Integer.valueOf(idObject.toString()); BIObject document = DAOFactory.getBIObjectDAO().loadBIObjectById(id); String docName = document.getName(); //Recover user Id HashedMap parameters = new HashedMap(); BasicXmlBuilder basic = new BasicXmlBuilder(docName); String template = basic.buildTemplate(kpiBlocks); String dirS = System.getProperty("java.io.tmpdir"); File dir = new File(dirS); dir.mkdirs(); tmpFile = File.createTempFile("tempXmlExport", ".xml", dir); FileOutputStream stream = new FileOutputStream(tmpFile); stream.write(template.getBytes()); stream.flush(); stream.close(); BufferedInputStream in = new BufferedInputStream(new FileInputStream(tmpFile)); in.close(); logger.debug("OUT"); return tmpFile; } catch (Throwable e) { logger.error("An exception has occured", e); throw new Exception(e); } finally { //tmpFile.delete(); } }
From source file:org.brekka.stillingar.spring.snapshot.WatchedResourceMonitorTest.java
/** * Test method for {@link org.brekka.stillingar.spring.snapshot.WatchedResourceMonitor#hasChanged()}. *//*ww w. j a va 2s .c om*/ @Test public void testHasChanged() throws Exception { File dir = new File(System.getProperty("java.io.tmpdir"), getClass().getSimpleName()); dir.mkdirs(); File file = new File(dir, "config.xml"); file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); watchedResourceMonitor.initialise(new FileSystemResource(file)); assertFalse(watchedResourceMonitor.hasChanged()); Thread.sleep(500); for (int i = 0; i < 3; i++) { fos.write("Test\n".getBytes()); fos.flush(); file.setLastModified(System.currentTimeMillis()); Thread.sleep(500); assertTrue(watchedResourceMonitor.hasChanged()); Thread.sleep(500); assertFalse(watchedResourceMonitor.hasChanged()); } fos.close(); file.delete(); dir.delete(); }
From source file:at.tuwien.minimee.migration.engines.MonitorEngineWinPslist.java
/** * Copies resource file 'from' from destination 'to' and set execution permission. * /* w w w . j av a 2 s . co m*/ * @param from * @param to * @throws Exception */ protected void copyFile(String from, String to, String workingDirectory) throws Exception { // // copy the shell script to the working directory // URL monitorCallShellScriptUrl = Thread.currentThread().getContextClassLoader().getResource(from); File f = new File(monitorCallShellScriptUrl.getFile()); String directoryPath = f.getAbsolutePath(); /* URL urlJar = new URL(directoryPath.substring( directoryPath.indexOf("file:"), directoryPath.indexOf("plato.jar")+"plato.jar".length())); JarFile jf = new JarFile(urlJar.getFile()); JarEntry je = jf.getJarEntry(from); String fileName = je.getName(); */ InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(from); File outScriptFile = new File(to); FileOutputStream fos = new FileOutputStream(outScriptFile); int nextChar; while ((nextChar = in.read()) != -1) { fos.write(nextChar); } fos.flush(); fos.close(); }