List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:de.hshannover.f4.trust.iron.mapserver.communication.http.BasicAccessAuthenticationTest.java
@Override @Before//from w w w. ja v a2 s . c om public void setUp() { // ugly, create a properties file "somewhere" for testing try { File f; do { testConf = "irond_test_" + System.nanoTime(); f = new File(testConf); } while (f.exists()); FileWriter fw = new FileWriter(f); BufferedWriter bw = new BufferedWriter(fw); bw.write("test:test"); bw.flush(); fw.close(); } catch (IOException e) { fail(e.getMessage()); } mServerConf = StubProvider.getServerConfStub(testConf); BasicAuthProvider provider = null; try { provider = new BasicAuthProviderPropImpl(mServerConf); } catch (ProviderInitializationException e) { fail("Cannot initialize the provider!"); } Socket s = new Socket(); mBasicAuth = new BasicChannelAuth(s, provider); }
From source file:TestSecurity.java
/** * put your documentation comment here/*from w w w . j a v a 2 s. co m*/ * @param req * @param res * @exception ServletException, IOException */ public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<HTML>"); out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>"); out.println("<BODY>"); out.println("<BIG>Test Security</BIG>"); try { out.println(h2o + "Information..." + h2c); out.println(" Security Manager: " + getSecurityManager().getClass().getName() + p); out.println(" ClassLoader: " + this.getClass().getClassLoader() + p); // weblogic.utils.classloaders.GenericClassLoader gcl = (weblogic.utils.classloaders.GenericClassLoader)this.getClass().getClassLoader(); // gcl.setDebug( true ); out.println(" CodeSource: " + this.getClass().getProtectionDomain().getCodeSource().getLocation() + p); out.println(" -- allowed -- " + p); } catch (Exception e) { out.println(" -- rejected -- " + e.getMessage() + p); } /* try { out.println( h2o + "Trying some dangerous J2EE calls..." + h2c ); String hack = request.getParameter( "hack" ); Cookie[] cookies = request.getCookies(); out.println( " -- allowed -- " + p ); int x = 1 + 2 + 3; out.println( hack ); // use it int y = 1 + 2 + 3; out.println( cookies ); // use it String m = "COOKIE: " + cookies[0]; // use it again cookies = new Cookie[10]; // reset it String n = "COOKIE: " + cookies[5]; // use it again } catch( Exception e ) { out.println( " -- rejected -- " + e.getMessage() + p ); } */ try { out.println(h2o + "Attempting file write to d:/Java..." + h2c); File f = new File("d:/Java/blah.txt"); FileWriter fw = new FileWriter(f); fw.write("test\n"); fw.close(); out.println(" -- allowed -- " + p); } catch (Exception e) { out.println(" -- rejected -- " + e.getMessage() + p); } try { out.println(h2o + "Attempting file write to d:/Java/TestServlet..." + h2c); File f = new File("d:/Java/TestServlet/blah.txt"); FileWriter fw = new FileWriter(f); fw.write("test\n"); fw.close(); out.println(" -- allowed -- " + p); } catch (Exception e) { out.println(" -- rejected -- " + e.getMessage() + p); } try { out.println(h2o + "Attempting file read to c:/Ntdetect..." + h2c); File f = new File("c:/Ntdetect.com"); FileReader fr = new FileReader(f); int c = fr.read(); out.println(" -- allowed -- " + p); } catch (Exception e) { out.println(" -- rejected -- " + e.getMessage() + p); } try { out.println(h2o + "Attempting file read to c:/weblogic/weblogic.properties..." + h2c); File f = new File("c:/weblogic/weblogic.properties"); FileReader fr = new FileReader(f); int c = fr.read(); out.println(" -- allowed -- " + p); } catch (Exception e) { out.println(" -- rejected -- " + e.getMessage() + p); } try { out.println(h2o + "Attempting to connect to yahoo.com..." + h2c); Socket s = new Socket("yahoo.com", 8080); out.println(" -- allowed -- " + p); } catch (Exception e) { out.println(" -- rejected -- " + e.getMessage() + p); } try { out.println(h2o + "Attempting to connect to hacker.com..." + h2c); Socket s = new Socket("hacker.com", 8080); out.println(" -- allowed -- " + p); } catch (Exception e) { out.println(" -- rejected -- " + e.getMessage() + p); } try { out.println(h2o + "Attempting to listen on port 37337..." + h2c); ServerSocket s = new ServerSocket(37337); Socket c = s.accept(); out.println(" -- allowed -- " + p); } catch (Exception e) { out.println(" -- rejected -- " + e.getMessage() + p); } try { out.println(h2o + "Attempting to listen on port 7001..." + h2c); ServerSocket s = new ServerSocket(7001); Socket c = s.accept(); out.println(" -- allowed -- " + p); } catch (Exception e) { out.println(" -- rejected -- " + e.getMessage() + p); } /* try { out.println( h2o + "Attempting native call..." + h2c ); native0( 1 ); out.println( " -- allowed -- " + p ); } catch( Exception e ) { out.println( " -- rejected -- " + e.getMessage() + p ); } */ try { out.println(h2o + "Attempting exec..." + h2c); Runtime.getRuntime().exec("dir"); out.println(" -- allowed -- " + p); } catch (Exception e) { out.println(" -- rejected -- " + e.getMessage() + p); } try { out.println(h2o + "Attempting system exit..." + h2c); out.println(" -- allowed -- " + p); } catch (Exception e) { out.println(" -- rejected -- " + e.getMessage() + p); } out.println("</BODY></HTML>"); }
From source file:com.highcharts.export.util.SVGCreator.java
private void writeFile(File file, String content) throws IOException { FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); try {/*from w w w .j a v a 2 s. c o m*/ bw.write(content); } finally { bw.close(); fw.close(); } }
From source file:net.itransformers.idiscover.v2.core.listeners.node.GraphmlFileLogDiscoveryListener.java
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { File baseDir = new File(projectPath, labelDirName); File xsltFile = new File(projectPath, xsltFileName); File graphmlDir = new File(baseDir, graphmlDirName); if (!graphmlDir.exists()) graphmlDir.mkdir();// www .j ava 2 s .co m String deviceName = discoveryResult.getNodeId(); if (deviceName == null) return; //This is a case of a subnetKind of a node or other nodes without nodeId. DiscoveredDeviceData discoveredDeviceData = (DiscoveredDeviceData) discoveryResult .getDiscoveredData("deviceData"); ByteArrayOutputStream graphMLOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { JaxbMarshalar.marshal(discoveredDeviceData, out, "DiscoveredDevice"); } catch (JAXBException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } XsltTransformer transformer = new XsltTransformer(); try { transformer.transformXML(new ByteArrayInputStream(out.toByteArray()), xsltFile, graphMLOutputStream, null); } catch (Exception e) { logger.error(e.getMessage(), e); } try { final String fileName = "node-" + deviceName + ".graphml"; // String fullFileName = path + File.separator + fileName; final File nodeFile = new File(graphmlDir, fileName); // System.out.println(new String(graphMLOutputStream.toByteArray())); String graphml = new XmlFormatter().format(new String(graphMLOutputStream.toByteArray())); FileUtils.writeStringToFile(nodeFile, graphml); FileWriter writer = new FileWriter(new File(labelDirName, "undirected" + ".graphmls"), true); writer.append(String.valueOf(fileName)).append("\n"); writer.close(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } }
From source file:bridge.toolkit.commands.PostProcess.java
/** * The unit of processing work to be performed for the PostProcess module. * @see org.apache.commons.chain.Command#execute(org.apache.commons.chain.Context) *//* w w w. j ava 2 s . co m*/ @Override public boolean execute(Context ctx) { System.out.println("Executing Post Process"); if ((ctx.get(Keys.XML_SOURCE) != null) && (ctx.get(Keys.CP_PACKAGE) != null)) { File cpPackage = (File) ctx.get(Keys.CP_PACKAGE); Document manifest = (Document) ctx.get(Keys.XML_SOURCE); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); File temp = new File(cpPackage + File.separator + "imsmanifest.xml"); try { //writes the imsmanfest.xml file out to the content package FileWriter writer = new FileWriter(temp, false); outputter.output(manifest, writer); writer.flush(); writer.close(); //copies the required xsd files over to the content package CopyDirectory cd = new CopyDirectory(); //check if the directory exists if it does use it else copy it from the jar File xsd_loc = new File(System.getProperty("user.dir") + File.separator + "xsd"); if (xsd_loc.exists()) { cd.copyDirectory(xsd_loc, cpPackage); } else { cd.CopyJarFiles(this.getClass(), "xsd", cpPackage.getAbsolutePath()); } } catch (java.io.IOException e) { System.out.println("Content Package creation was unsuccessful"); e.printStackTrace(); return PROCESSING_COMPLETE; } //get the organization title from the manifest file //replace any white spaces with Element title = null; XPath xp = null; try { xp = XPath.newInstance("//ns:organization//ns:title"); xp.addNamespace("ns", "http://www.imsglobal.org/xsd/imscp_v1p1"); title = (Element) xp.selectSingleNode(manifest); } catch (JDOMException e) { System.out.println("Content Package creation was unsuccessful"); e.printStackTrace(); return PROCESSING_COMPLETE; } String outputPath = ""; if (ctx.get(Keys.OUTPUT_DIRECTORY) != null) { outputPath = (String) ctx.get(Keys.OUTPUT_DIRECTORY); if (outputPath.length() > 0) { outputPath = outputPath + File.separator; } } File outputDir = new File(outputPath); if (!outputDir.exists()) { outputDir.mkdirs(); } String zipName = title.getValue(); zipName = zipName.replace(" ", "_").trim(); zipName = zipName.replace("\n", "").trim(); File zip = new File(zipName + ".zip"); if (!outputDir.getName().equals("")) zip = new File(outputDir + File.separator + zipName + ".zip"); ZipCreator zipCreator = new ZipCreator(); try { zipCreator.zipFiles(cpPackage, zip); } catch (IOException e) { System.out.println("Content Package creation was unsuccessful"); e.printStackTrace(); return PROCESSING_COMPLETE; } cpPackage.deleteOnExit(); System.out.println("Content Package creation was successful"); } else { System.out.println("Content Package creation was unsuccessful"); System.out.println("One of the required Context entries for the " + this.getClass().getSimpleName() + " command to be executed was null"); return PROCESSING_COMPLETE; } return CONTINUE_PROCESSING; }
From source file:net.lmxm.ute.beans.configuration.ApplicationPreferences.java
/** * Creates the empty preferences file.//from ww w . j a va 2s. c o m * * @param preferencesFile the preferences file */ private void createEmptyPreferencesFile(final File preferencesFile) { final String prefix = "createEmptyPreferencesFile() :"; LOGGER.debug("{} entered, preferencesFile={}", prefix, preferencesFile); try { if (preferencesFile.createNewFile()) { LOGGER.debug("{} preferences file created successfully", prefix); } else { LOGGER.error("{} unable to create preferences file", prefix); throw new ConfigurationException(ExceptionResourceType.PREFERENCES_FILE_ALREADY_EXISTS); } final FileWriter fileWriter = new FileWriter(preferencesFile); fileWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><preferences/>"); fileWriter.close(); } catch (final IOException e) { LOGGER.error("{} unable to create empty preferences file", prefix); throw new ConfigurationException(ExceptionResourceType.ERROR_CREATING_PREFERENCES_FILE, e); } LOGGER.debug("{} leaving", prefix); }
From source file:Utilitarios.Imprimir.java
public void imprimirGrafico(Image image) throws IOException { FileWriter arq = new FileWriter("D:\\Orcamentos\\Grafico.doc");//cria o arquivo PrintWriter gravarArq = new PrintWriter(arq); gravarArq.println("Oramento Banzos Instituto de Msica "); //linha de conteudo do txt gravarArq.println(" "); gravarArq.println(image);/*from w ww .ja va2 s .c o m*/ arq.close(); }
From source file:io.onedecision.engine.decisions.converter.DecisionModelConverterTest.java
@Test @Ignore //author direct in dmn? public void testConvertSingleDecisionTable() throws JsonParseException, JsonMappingException, IOException, DecisionException { DecisionModel jsonModel = getJsonModel(ARR_JSON_RESOURCE); converter.setDomainModelFactory(//from ww w. jav a 2 s. co m new MockDomainModelFactory("http://onedecision.io/health", "/domains/health.json")); Definitions dmnModel = converter.convert(jsonModel); Decision d = dmnModel.getDecision(ARR_DECISION_ID); assertNotNull(d); DecisionTable dt = d.getDecisionTable(); assertNotNull(dt); assertEquals(3, dt.getInputs().size()); assertEquals(5, dt.getRules().size()); for (DecisionRule rule : dt.getRules()) { assertEquals(2, rule.getInputEntry().size()); assertEquals(1, rule.getOutputEntry().size()); } File dmnFile = new File("target", ARR_DEFINITION_ID + ".dmn"); FileWriter writer = null; try { writer = new FileWriter(dmnFile); new DecisionModelFactory().write(dmnModel, writer); } finally { try { writer.close(); } catch (Exception e) { } } assertTrue(dmnFile.exists()); // TODO validate the result using all registered validators // http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html SchemaValidator schemaValidator = new SchemaValidator(); DmnValidationErrors errors = new DmnValidationErrors(dmnFile.getName()); schemaValidator.validate(new FileInputStream(dmnFile), errors); assertEquals(0, errors.getErrorCount()); }
From source file:com.googlecode.fascinator.portal.services.impl.PortalManagerImpl.java
@Override public void save(Portal portal) { String portalName = portal.getName(); File portalFile = new File(new File(portalsDir, FilenameUtils.normalize(portalName)), PORTAL_JSON); portalFile.getParentFile().mkdirs(); try {/* ww w.ja v a 2 s . co m*/ FileWriter writer = new FileWriter(portalFile); writer.write(portal.toString(true)); writer.close(); } catch (IOException ioe) { } }
From source file:com.krikelin.spotifysource.AppInstaller.java
protected void copyFile(String src, String dest) throws IOException { File inputFile = new File(src); File outputFile = new File(dest); FileReader in = new FileReader(inputFile); FileWriter out = new FileWriter(outputFile); int c;//from w ww. jav a2s .co m while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); }