本文整理汇总了Java中com.intellij.util.LineSeparator.LF属性的典型用法代码示例。如果您正苦于以下问题:Java LineSeparator.LF属性的具体用法?Java LineSeparator.LF怎么用?Java LineSeparator.LF使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.intellij.util.LineSeparator
的用法示例。
在下文中一共展示了LineSeparator.LF属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTempFile
@NotNull
private static File createTempFile(@NotNull final DocumentContent content, @NotNull String tempFileName) throws IOException {
FileDocumentManager.getInstance().saveDocument(content.getDocument());
LineSeparator separator = content.getLineSeparator();
if (separator == null) separator = LineSeparator.getSystemLineSeparator();
Charset charset = content.getCharset();
if (charset == null) charset = Charset.defaultCharset();
String contentData = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
return content.getDocument().getText();
}
});
if (separator != LineSeparator.LF) {
contentData = StringUtil.convertLineSeparators(contentData, separator.getSeparatorString());
}
byte[] bytes = contentData.getBytes(charset);
return createFile(bytes, tempFileName);
}
示例2: createSeparatorPanel
@NotNull
private static JComponent createSeparatorPanel(@NotNull LineSeparator separator) {
JLabel label = new JLabel(separator.name());
Color color;
if (separator == LineSeparator.CRLF) {
color = JBColor.RED;
}
else if (separator == LineSeparator.LF) {
color = JBColor.BLUE;
}
else if (separator == LineSeparator.CR) {
color = JBColor.MAGENTA;
}
else {
color = JBColor.BLACK;
}
label.setForeground(color);
return label;
}
示例3: createSeparatorPanel
@Nonnull
private static JComponent createSeparatorPanel(@Nonnull LineSeparator separator) {
JLabel label = new JLabel(separator.name());
Color color;
if (separator == LineSeparator.CRLF) {
color = JBColor.RED;
}
else if (separator == LineSeparator.LF) {
color = JBColor.BLUE;
}
else if (separator == LineSeparator.CR) {
color = JBColor.MAGENTA;
}
else {
color = JBColor.BLACK;
}
label.setForeground(color);
return label;
}
示例4: detectLineSeparators
private static LineSeparator detectLineSeparators(String actual) {
char[] chars = CharArrayUtil.fromSequence(actual);
for (char c : chars) {
if (c == '\r') {
return LineSeparator.CRLF;
}
else if (c == '\n') { // if we are here, there was no \r before
return LineSeparator.LF;
}
}
return LineSeparator.LF;
}
示例5: createTempFile
@Nonnull
private static File createTempFile(@Nonnull final DocumentContent content, @Nonnull FileNameInfo fileName) throws IOException {
FileDocumentManager.getInstance().saveDocument(content.getDocument());
LineSeparator separator = content.getLineSeparator();
if (separator == null) separator = LineSeparator.getSystemLineSeparator();
Charset charset = content.getCharset();
if (charset == null) charset = Charset.defaultCharset();
Boolean hasBom = content.hasBom();
if (hasBom == null) hasBom = CharsetToolkit.getMandatoryBom(charset) != null;
String contentData = ReadAction.compute(() -> {
return content.getDocument().getText();
});
if (separator != LineSeparator.LF) {
contentData = StringUtil.convertLineSeparators(contentData, separator.getSeparatorString());
}
byte[] bytes = contentData.getBytes(charset);
byte[] bom = hasBom ? CharsetToolkit.getPossibleBom(charset) : null;
if (bom != null) {
bytes = ArrayUtil.mergeArrays(bom, bytes);
}
return createFile(bytes, fileName);
}
示例6: detectLineSeparators
@Nonnull
public static LineSeparator detectLineSeparators(@Nonnull CharSequence chars, @Nullable LineSeparator defaultSeparator) {
for (int i = 0, n = chars.length(); i < n; i++) {
char c = chars.charAt(i);
if (c == '\r') {
return LineSeparator.CRLF;
}
else if (c == '\n') {
// if we are here, there was no \r before
return LineSeparator.LF;
}
}
return defaultSeparator == null ? LineSeparator.getSystemLineSeparator() : defaultSeparator;
}
示例7: doSave
@Override
protected void doSave(@Nullable Element element) throws IOException {
if (myLineSeparator == null) {
myLineSeparator = isUseLfLineSeparatorByDefault() ? LineSeparator.LF : LineSeparator.getSystemLineSeparator();
}
BufferExposingByteArrayOutputStream content = element == null ? null : StorageUtil.writeToBytes(element, myLineSeparator.getSeparatorString());
if (ApplicationManager.getApplication().isUnitTestMode() && StringUtil.startsWithChar(myFile.getPath(), '$')) {
throw new StateStorageException("It seems like some macros were not expanded for path: " + myFile.getPath());
}
try {
if (myStreamProvider != null && myStreamProvider.isEnabled()) {
// stream provider always use LF separator
saveForProvider(myLineSeparator == LineSeparator.LF ? content : null, element);
}
}
catch (Throwable e) {
LOG.error(e);
}
if (content == null) {
StorageUtil.deleteFile(myFile, this, getVirtualFile());
myCachedVirtualFile = null;
}
else {
VirtualFile file = getVirtualFile();
if (file == null || !file.exists()) {
FileUtil.createParentDirs(myFile);
file = null;
}
myCachedVirtualFile = StorageUtil.writeFile(myFile, this, file, content, isUseXmlProlog() ? myLineSeparator : null);
}
}
示例8: ConvertToUnixLineSeparatorsAction
public ConvertToUnixLineSeparatorsAction() {
super(ApplicationBundle.message("combobox.crlf.unix"), LineSeparator.LF);
}