List of usage examples for org.apache.commons.io IOUtils LINE_SEPARATOR_WINDOWS
String LINE_SEPARATOR_WINDOWS
To view the source code for org.apache.commons.io IOUtils LINE_SEPARATOR_WINDOWS.
Click Source Link
From source file:com.mirth.connect.util.messagewriter.MessageWriterFile.java
@Override public boolean write(Message message) throws MessageWriterException { try {/* ww w. ja v a2 s . c om*/ String file = path + IOUtils.DIR_SEPARATOR; String content = null; boolean replaced = false; if (contentType == null) { // If we're serializing and encrypting the message, we have to do replacement first if (encrypted) { file += replacer.replaceValues(filePattern, message); replaced = true; } content = toXml(message); } else { content = extractContent(message); } if (StringUtils.isNotBlank(content)) { // Do the replacement here if we haven't already if (!replaced) { file += replacer.replaceValues(filePattern, message); } if (!file.equals(currentFile)) { if (writer != null) { writer.close(); } currentFile = file; File fileObject = new File(file); if (fileObject.isDirectory()) { throw new MessageWriterException( "Cannot save message to file \"" + file + "\", it is a directory"); } writer = new OutputStreamWriter(FileUtils.openOutputStream(fileObject, true)); } writer.write(content); writer.append(IOUtils.LINE_SEPARATOR_WINDOWS); // windows newlines were required previously when commons-vfs was used writer.flush(); return true; } return false; } catch (Exception e) { throw new MessageWriterException(e); } }
From source file:com.mirth.connect.util.messagewriter.MessageWriterVfs.java
@Override public boolean write(Message message) throws MessageWriterException { try {/*ww w .j a va 2 s. co m*/ String content = (contentType == null) ? toXml(message) : extractContent(message); if (StringUtils.isNotBlank(content)) { String file = uri + IOUtils.DIR_SEPARATOR + replacer.replaceValues(filePattern, message, false); if (!file.equals(currentFile)) { if (writer != null) { writer.close(); } if (currentFileObject != null) { currentFileObject.close(); } currentFile = file; currentFileObject = VFS.getManager().resolveFile(file); if (currentFileObject.getType() == FileType.FOLDER) { throw new MessageWriterException( "Cannot save message to file \"" + file + "\", it is a directory"); } writer = new OutputStreamWriter(currentFileObject.getContent().getOutputStream(true)); } writer.write(content); writer.append(IOUtils.LINE_SEPARATOR_WINDOWS); // the VFS output stream requires windows newlines writer.flush(); return true; } return false; } catch (Exception e) { throw new MessageWriterException(e); } }
From source file:com.mirth.connect.util.messagewriter.MessageWriterVfs.java
private String extractContent(Message message) { StringBuilder stringBuilder = new StringBuilder(); for (Entry<Integer, ConnectorMessage> entry : message.getConnectorMessages().entrySet()) { Integer metaDataId = entry.getKey(); ConnectorMessage connectorMessage = entry.getValue(); if (((destinationContent && metaDataId != 0) || (!destinationContent && metaDataId == 0))) { MessageContent messageContent = connectorMessage.getMessageContent(contentType); if (messageContent != null) { String content = messageContent.getContent(); if (encrypted) { if (!messageContent.isEncrypted()) { content = encryptor.encrypt(content); }//from w w w. j ava 2s . c o m } else { if (messageContent.isEncrypted()) { content = encryptor.decrypt(content); } } if (StringUtils.isNotBlank(content)) { stringBuilder.append(content); stringBuilder.append(IOUtils.LINE_SEPARATOR_WINDOWS); // the VFS output stream requires windows newlines stringBuilder.append(IOUtils.LINE_SEPARATOR_WINDOWS); } } } } return stringBuilder.toString(); }
From source file:com.mirth.connect.util.messagewriter.MessageWriterFile.java
private String extractContent(Message message) { StringBuilder stringBuilder = new StringBuilder(); for (Entry<Integer, ConnectorMessage> entry : message.getConnectorMessages().entrySet()) { Integer metaDataId = entry.getKey(); ConnectorMessage connectorMessage = entry.getValue(); if (((destinationContent && metaDataId != 0) || (!destinationContent && metaDataId == 0))) { Content content = null;//from w ww . j ava 2 s . c om if (contentType == ContentType.SOURCE_MAP) { content = message.getMergedConnectorMessage().getSourceMapContent(); } else if (contentType == ContentType.CHANNEL_MAP) { content = message.getMergedConnectorMessage().getChannelMapContent(); } else if (contentType == ContentType.RESPONSE_MAP) { content = message.getMergedConnectorMessage().getResponseMapContent(); } else { content = connectorMessage.getMessageContent(contentType); } if (content != null) { String stringContent = null; boolean contentEncrypted = content.isEncrypted(); if (contentType == ContentType.SENT) { String tempContent = (String) content.getContent(); if (contentEncrypted) { tempContent = encryptor.decrypt(tempContent); contentEncrypted = false; } if (StringUtils.isNotEmpty(tempContent)) { ConnectorProperties sentContent = serializer.deserialize(tempContent, ConnectorProperties.class); stringContent = sentContent.toFormattedString(); } } else if (content instanceof MapContent) { /* * We don't need to check if the content is encrypted because map content is * always decrypted when it is retrieved by JdbcDao */ @SuppressWarnings("unchecked") Map<String, Object> tempContent = (Map<String, Object>) content.getContent(); if (MapUtils.isNotEmpty(tempContent)) { stringContent = MapUtil.serializeMap(serializer, tempContent); } } else { stringContent = (String) content.getContent(); } if (StringUtils.isNotEmpty(stringContent)) { if (encrypted) { if (!contentEncrypted) { stringContent = encryptor.encrypt(stringContent); } } else { if (contentEncrypted) { stringContent = encryptor.decrypt(stringContent); } } if (StringUtils.isNotBlank(stringContent)) { stringBuilder.append(stringContent); stringBuilder.append(IOUtils.LINE_SEPARATOR_WINDOWS); // the VFS output stream requires windows newlines stringBuilder.append(IOUtils.LINE_SEPARATOR_WINDOWS); } } } } } return stringBuilder.toString(); }
From source file:net.sourceforge.pmd.docs.MockedFileWriter.java
public static String normalizeLineSeparators(String s) { return s.replaceAll(Pattern.quote(IOUtils.LINE_SEPARATOR_WINDOWS), IOUtils.LINE_SEPARATOR_UNIX) .replaceAll(Pattern.quote(IOUtils.LINE_SEPARATOR_UNIX), PMD.EOL); }
From source file:net.sourceforge.pmd.renderers.YAHTMLRendererTest.java
private static String normalizeLineSeparators(String s) { return s.replaceAll(Pattern.quote(IOUtils.LINE_SEPARATOR_WINDOWS), IOUtils.LINE_SEPARATOR_UNIX) .replaceAll(Pattern.quote(IOUtils.LINE_SEPARATOR_UNIX), PMD.EOL); }
From source file:org.archive.util.FileUtilsTest.java
protected void setUp() throws Exception { super.setUp(); this.srcDirFile = new File(getTmpDir(), srcDirName); FileUtils.ensureWriteableDirectory(srcDirFile); this.tgtDirFile = new File(getTmpDir(), tgtDirName); FileUtils.ensureWriteableDirectory(tgtDirFile); addFiles();//from ww w .j av a 2s.c o m zeroLengthLinesUnix = setUpLinesFile("zeroLengthLinesUnix", 0, 0, 400, IOUtils.LINE_SEPARATOR_UNIX); zeroLengthLinesWindows = setUpLinesFile("zeroLengthLinesUnix", 0, 0, 400, IOUtils.LINE_SEPARATOR_WINDOWS); smallLinesUnix = setUpLinesFile("smallLinesUnix", 0, 25, 400, IOUtils.LINE_SEPARATOR_UNIX); smallLinesWindows = setUpLinesFile("smallLinesWindows", 0, 25, 400, IOUtils.LINE_SEPARATOR_WINDOWS); largeLinesUnix = setUpLinesFile("largeLinesUnix", 128, 256, 5, IOUtils.LINE_SEPARATOR_UNIX); largeLinesWindows = setUpLinesFile("largeLinesWindows", 128, 256, 4096, IOUtils.LINE_SEPARATOR_WINDOWS); nakedLastLineUnix = setUpLinesFile("nakedLastLineUnix", 0, 50, 401, IOUtils.LINE_SEPARATOR_UNIX); org.apache.commons.io.FileUtils.writeStringToFile(nakedLastLineUnix, "a"); nakedLastLineWindows = setUpLinesFile("nakedLastLineWindows", 0, 50, 401, IOUtils.LINE_SEPARATOR_WINDOWS); org.apache.commons.io.FileUtils.writeStringToFile(nakedLastLineWindows, "a"); }
From source file:org.jasig.maven.notice.CheckNoticeMojoTest.java
public void copyFileWithOppositeLineEnding(File src, File dst) throws IOException { final List<String> lines = FileUtils.readLines(src); if (IOUtils.LINE_SEPARATOR_UNIX.equals(IOUtils.LINE_SEPARATOR)) { FileUtils.writeLines(dst, lines, IOUtils.LINE_SEPARATOR_WINDOWS); } else {/*from ww w . j av a2 s.co m*/ FileUtils.writeLines(dst, lines, IOUtils.LINE_SEPARATOR_UNIX); } }
From source file:org.raml.v2.internal.framework.suggester.SuggesterTestCase.java
@Test public void verifySuggestion() throws IOException { final RamlSuggester ramlSuggester = new RamlSuggester(); String content = IOUtils.toString(new FileInputStream(input), "UTF-8"); if (IS_OS_WINDOWS) { content = content.replace(IOUtils.LINE_SEPARATOR_WINDOWS, IOUtils.LINE_SEPARATOR_UNIX); }//from www. java2 s .c o m final int offset = content.indexOf(CURSOR_KEYWORD); final String document = content.substring(0, offset) + content.substring(offset + CURSOR_KEYWORD.length()); final List<Suggestion> suggestions = ramlSuggester.suggestions(document, offset - 1).getSuggestions(); final ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); dump = ow.writeValueAsString(suggestions); expected = IOUtils.toString(new FileInputStream(this.expectedOutput)); Assert.assertTrue(jsonEquals(dump, expected)); }
From source file:org.sonar.colorizer.CodeColorizerTest.java
@Test public void shouldSupportWindowsEndOfLines() throws IOException { Reader windowsFile = readFile("/org/sonar/colorizer/samples/Sample.java", IOUtils.LINE_SEPARATOR_WINDOWS); String html = CodeColorizer.javaToHtml(windowsFile, HtmlOptions.DEFAULT); assertHtml(html);/*from www . jav a 2s.c om*/ assertContains(html, "<pre><span class=\"k\">public</span> <span class=\"k\">class</span> Sample {</pre>"); }