List of usage examples for org.apache.commons.io FileUtils writeStringToFile
public static void writeStringToFile(File file, String data) throws IOException
From source file:net.itransformers.idiscover.v2.core.listeners.RawDataFileLogDiscoveryListener.java
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { File baseDir = new File(projectPath, labelDirName); if (!baseDir.exists()) baseDir.mkdir();//from w w w . j a v a2s . c o m File rawDataDir = new File(baseDir, rawDataDirName); if (!rawDataDir.exists()) rawDataDir.mkdir(); String deviceName = discoveryResult.getNodeId(); File file = new File(rawDataDir, deviceName + ".xml"); String rawDataXml = new String((byte[]) discoveryResult.getDiscoveredData("rawData")); try { FileUtils.writeStringToFile(file, rawDataXml); } catch (IOException e) { logger.error(e); } }
From source file:com.teotigraphix.caustk.service.SerializeService.java
@Override public void save(File target, Object serialized) throws IOException { String data = JsonUtils.toGson(serialized, true); FileUtils.writeStringToFile(target, data); }
From source file:de.alpharogroup.io.StringOutputStreamTest.java
/** * Test method for {@link StringOutputStream#toString()} * * @throws IOException/*from w w w . j av a 2s. c o m*/ * Signals that an I/O exception has occurred. */ @Test public void testToString() throws IOException { final String expected = "Thu Apr 19 00:00:00 CEST 2012"; final File writeInMe = new File(".", "testWriteBirthdayToFile.log"); FileUtils.writeStringToFile(writeInMe, expected); final InputStream inputStream = writeInMe.toURI().toURL().openStream(); final StringOutputStream stringOutput = new StringOutputStream(); final byte[] buffer = new byte[8192]; int readLength; while ((readLength = inputStream.read(buffer, 0, buffer.length)) != -1) { stringOutput.write(buffer, 0, readLength); } final String actual = stringOutput.toString(); stringOutput.close(); AssertJUnit.assertTrue("", actual.startsWith(expected)); FileUtils.deleteQuietly(writeInMe); }
From source file:com.thoughtworks.go.util.StringUtilTest.java
@Test public void shouldCalculateSha1Digest() throws IOException { File tempFile = TestFileUtil.createTempFile("for_digest.test"); FileUtils.writeStringToFile(tempFile, "12345"); assertThat(StringUtil.sha1Digest(tempFile), is("jLIjfQZ5yojbZGTqxg2pY0VROWQ=")); }
From source file:hudson.maven.settings.SettingsProviderUtils.java
/** * //from www . ja va 2 s.co m * @return a temp file which must be deleted after use */ public static File copyConfigContentToFile(Config config) throws IOException { File tmpContentFile = File.createTempFile("config", "tmp"); FileUtils.writeStringToFile(tmpContentFile, config.content); return tmpContentFile; }
From source file:cl.almejo.vsim.gui.actions.preferences.ColorPreferences.java
public ColorPreferences(Component parent) { _parent = parent;//from w w w . ja va2 s. co m setBorder(new EmptyBorder(10, 10, 10, 10)); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JPanel pickers = new JPanel(); pickers.setLayout(new GridLayout(10, 2)); pickers.add(new Label(Messages.t("preferences.color.scheme.current.label"))); _comboBox = createSchemeCombobox(); pickers.add(_comboBox); addColorChooser(pickers, "gates"); addColorChooser(pickers, "background"); addColorChooser(pickers, "bus-on"); addColorChooser(pickers, "ground"); addColorChooser(pickers, "off"); addColorChooser(pickers, "wires-on"); addColorChooser(pickers, "signal"); addColorChooser(pickers, "grid"); addColorChooser(pickers, "label"); add(pickers); JPanel buttons = new JPanel(); JButton button = new JButton(Messages.t("preferences.color.scheme.save.label")); buttons.add(button); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { FileUtils.writeStringToFile(new File("colors.json"), ColorScheme.save()); } catch (IOException e1) { e1.printStackTrace(); } } }); button = new JButton(Messages.t("preferences.color.scheme.new.label")); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String themeName = JOptionPane.showInputDialog(Messages.t("color.scheme.dialog.new.title"), ""); if (themeName != null) { while (ColorScheme.exists(themeName)) { JOptionPane.showMessageDialog(_parent, Messages.t("color.scheme.dialog.already.exists.error"), "Error", JOptionPane.ERROR_MESSAGE); themeName = JOptionPane.showInputDialog(this, themeName); } ColorScheme.add(themeName); _comboBox.addItem(themeName); _comboBox.setSelectedItem(themeName); } } }); buttons.add(button); add(buttons); }
From source file:jenkins.plugins.shiningpanda.utils.TestFilePathUtil.java
public void testExistsOrNullExists() throws Exception { File file = new File(createTmpDir(), "file.txt"); FileUtils.writeStringToFile(file, "hello"); FilePath filePath = FilePathUtil.existsOrNull(new FilePath(file)); assertNotNull("file exists, this should not return null", filePath); }
From source file:io.cloudslang.lang.compiler.SlangSourceTest.java
private void assertSourceEquals(String nameSuffix, Extension expectedExtension) throws IOException { String name = nameWithoutExtension + nameSuffix; File file = folder.newFile(name); FileUtils.writeStringToFile(file, content); SlangSource source = SlangSource.fromFile(file); Assert.assertEquals(content, source.getContent()); Assert.assertEquals(name, source.getName()); Assert.assertEquals(expectedExtension, source.getFileExtension()); Assert.assertTrue(source.getFilePath().endsWith(name)); }
From source file:com.github.neio.filesystem.paths.TestFilePath.java
@Test public void testTouch() throws InterruptedException, IOException { File testFile = new File(testDir, "testFile"); FileUtils.writeStringToFile(testFile, "Hello World"); long initialTime = testFile.lastModified(); TimeUnit.SECONDS.sleep(1);/* www. j a v a 2 s. c o m*/ new FilePath("./testTempDir/testFile").touch(); Assert.assertTrue(initialTime < testFile.lastModified()); }
From source file:beans.LogSmtp.java
@Override protected void append(ILoggingEvent eventObject) { try {//ww w . j av a 2s.c om if (ApplicationContext.get().conf().sendErrorEmails) { GsMailer.GsMailConfiguration mail = new GsMailer.GsMailConfiguration(); // TODO : move configuration to configuration files. // TODO : add dev mode support mail.setSubject("Error occured"); mail.addRecipient(GsMailer.RecipientType.TO, "guym@gigaspaces.com", "Guy Mograbi"); mail.setBodyText(eventObject.getFormattedMessage()); mail.setFrom("it@gigaspaces.com", "gigaspaces"); ApplicationContext.get().getMailer().send(mail); } } catch (Exception e) { Writer writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); // if we write errors to log here, we will end up here again.. infinite loop.. :( File file = new File("appender_problems_" + System.currentTimeMillis() + ".error"); try { FileUtils.writeStringToFile(file, writer.toString()); } catch (IOException e1) { System.out.println("unable to print appender errors."); } } }