public final class LoadTextUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
LoadTextUtil.AutoDetectionReason |
static class |
LoadTextUtil.DetectResult |
Modifier and Type | Method and Description |
---|---|
static void |
changeLineSeparators(Project project,
VirtualFile file,
java.lang.String newSeparator,
java.lang.Object requestor) |
static Pair.NonNull<java.nio.charset.Charset,byte[]> |
charsetForWriting(Project project,
VirtualFile virtualFile,
java.lang.String text,
java.nio.charset.Charset existing) |
static java.nio.charset.Charset |
charsetFromContentOrNull(Project project,
VirtualFile virtualFile,
java.lang.CharSequence text) |
static Pair.NonNull<java.nio.charset.Charset,byte[]> |
chooseMostlyHarmlessCharset(java.nio.charset.Charset existing,
java.nio.charset.Charset specified,
java.lang.String text) |
static void |
clearCharsetAutoDetectionReason(VirtualFile virtualFile) |
static java.nio.charset.Charset |
detectCharsetAndSetBOM(VirtualFile virtualFile,
byte [] content,
FileType fileType) |
static java.lang.String |
detectLineSeparator(VirtualFile file,
boolean checkFile)
Get detected line separator, if the file never been loaded, is loaded if checkFile parameter is specified.
|
static java.nio.charset.Charset |
extractCharsetFromFileContent(Project project,
VirtualFile virtualFile,
java.lang.CharSequence text) |
static LoadTextUtil.AutoDetectionReason |
getCharsetAutoDetectionReason(VirtualFile virtualFile) |
static java.lang.CharSequence |
getTextByBinaryPresentation(byte [] bytes,
java.nio.charset.Charset charset) |
static java.lang.CharSequence |
getTextByBinaryPresentation(byte [] bytes,
VirtualFile virtualFile) |
static java.lang.CharSequence |
getTextByBinaryPresentation(byte [] bytes,
VirtualFile virtualFile,
boolean saveDetectedSeparators,
boolean saveBOM) |
static java.lang.String |
getTextFromBytesOrNull(byte [] bytes,
int startOffset,
int endOffset)
Tries to detect text in the
bytes and call the fileTextProcessor with the text (if detected) or with null if not |
static LoadTextUtil.DetectResult |
guessFromContent(VirtualFile virtualFile,
byte [] content) |
static java.lang.CharSequence |
loadText(VirtualFile file) |
static java.lang.CharSequence |
loadText(VirtualFile file,
int limit)
Loads content of given virtual file.
|
static FileType |
processTextFromBinaryPresentationOrNull(byte [] bytes,
int length,
VirtualFile virtualFile,
boolean saveDetectedSeparators,
boolean saveBOM,
FileType fileType,
NotNullFunction<? super java.lang.CharSequence,? extends FileType> fileTextProcessor) |
static void |
write(Project project,
VirtualFile virtualFile,
java.lang.Object requestor,
java.lang.String text,
long newModificationStamp)
Overwrites file with text and sets modification stamp and time stamp to the specified values.
|
public static java.nio.charset.Charset detectCharsetAndSetBOM(VirtualFile virtualFile, byte [] content, FileType fileType)
public static LoadTextUtil.DetectResult guessFromContent(VirtualFile virtualFile, byte [] content)
public static java.lang.String getTextFromBytesOrNull(byte [] bytes, int startOffset, int endOffset)
bytes
and call the fileTextProcessor
with the text (if detected) or with null if notpublic static void changeLineSeparators(Project project, VirtualFile file, java.lang.String newSeparator, java.lang.Object requestor) throws java.io.IOException
java.io.IOException
public static void write(Project project, VirtualFile virtualFile, java.lang.Object requestor, java.lang.String text, long newModificationStamp) throws java.io.IOException
requestor
- any object to control who called this method. Note that
it is considered to be an external change if requestor
is null
.
See VirtualFileEvent.getRequestor()
newModificationStamp
- new modification stamp or -1 if no special value should be set @return Writer
java.io.IOException
- if an I/O error occursVirtualFile.getModificationStamp()
public static Pair.NonNull<java.nio.charset.Charset,byte[]> charsetForWriting(Project project, VirtualFile virtualFile, java.lang.String text, java.nio.charset.Charset existing)
public static Pair.NonNull<java.nio.charset.Charset,byte[]> chooseMostlyHarmlessCharset(java.nio.charset.Charset existing, java.nio.charset.Charset specified, java.lang.String text)
public static java.nio.charset.Charset extractCharsetFromFileContent(Project project, VirtualFile virtualFile, java.lang.CharSequence text)
public static java.nio.charset.Charset charsetFromContentOrNull(Project project, VirtualFile virtualFile, java.lang.CharSequence text)
public static java.lang.CharSequence loadText(VirtualFile file)
public static java.lang.CharSequence loadText(VirtualFile file, int limit)
file
- Virtual file for content loadinglimit
- Maximum characters count or java.lang.IllegalArgumentException
- for binary filespublic static java.lang.CharSequence getTextByBinaryPresentation(byte [] bytes, VirtualFile virtualFile)
public static java.lang.CharSequence getTextByBinaryPresentation(byte [] bytes, VirtualFile virtualFile, boolean saveDetectedSeparators, boolean saveBOM)
public static FileType processTextFromBinaryPresentationOrNull(byte [] bytes, int length, VirtualFile virtualFile, boolean saveDetectedSeparators, boolean saveBOM, FileType fileType, NotNullFunction<? super java.lang.CharSequence,? extends FileType> fileTextProcessor)
public static java.lang.String detectLineSeparator(VirtualFile file, boolean checkFile)
file
- the file to checkcheckFile
- if the line separator was not detected before, try to detect itpublic static java.lang.CharSequence getTextByBinaryPresentation(byte [] bytes, java.nio.charset.Charset charset)
public static LoadTextUtil.AutoDetectionReason getCharsetAutoDetectionReason(VirtualFile virtualFile)
public static void clearCharsetAutoDetectionReason(VirtualFile virtualFile)