use of com.intellij.util.text.CharSequenceReader in project go-lang-idea-plugin by go-lang-plugin-org.
the class JsonReaderEx method asGson.
@NotNull
public JsonReader asGson() {
JsonToken nextToken = peek();
switch(nextToken) {
case BEGIN_ARRAY:
case BEGIN_OBJECT:
case STRING:
case NUMBER:
case BOOLEAN:
break;
default:
throw createParseError("Cannot create sub reader, next token " + nextToken + " is not value");
}
CharSequence sequence = position > 0 ? in.subSequence(position - 1, in.length()) : in;
return new JsonReader(new CharSequenceReader(sequence));
}
use of com.intellij.util.text.CharSequenceReader in project ideavim by JetBrains.
the class ProcessGroup method executeCommand.
@NotNull
public String executeCommand(@NotNull String command, @Nullable CharSequence input) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("command=" + command);
}
final Process process = Runtime.getRuntime().exec(command);
if (input != null) {
final BufferedWriter outputWriter = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
copy(new CharSequenceReader(input), outputWriter);
outputWriter.close();
}
final BufferedReader inputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
final StringWriter writer = new StringWriter();
copy(inputReader, writer);
writer.close();
lastCommand = command;
return writer.toString();
}
use of com.intellij.util.text.CharSequenceReader in project intellij-plugins by JetBrains.
the class FlexCompilerConfigFileUtil method getNamespacesInfos.
public static Collection<NamespacesInfo> getNamespacesInfos(final VirtualFile configFile) {
if (configFile == null || !configFile.isValid() || configFile.isDirectory()) {
return Collections.emptyList();
}
Pair<Long, Collection<NamespacesInfo>> data = configFile.getUserData(MOD_STAMP_TO_NAMESPACES_INFOS);
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
final Document cachedDocument = documentManager.getCachedDocument(configFile);
final Long currentTimestamp = cachedDocument != null ? cachedDocument.getModificationStamp() : configFile.getModificationCount();
final Long cachedTimestamp = data == null ? null : data.first;
if (cachedTimestamp == null || !cachedTimestamp.equals(currentTimestamp)) {
data = null;
configFile.putUserData(MOD_STAMP_TO_NAMESPACES_INFOS, data);
try {
final NamespacesXmlBuilder builder = new NamespacesXmlBuilder();
if (cachedDocument != null) {
//noinspection IOResourceOpenedButNotSafelyClosed
NanoXmlUtil.parse(new CharSequenceReader(cachedDocument.getCharsSequence()), builder);
} else {
NanoXmlUtil.parse(configFile.getInputStream(), builder);
}
final Collection<NamespacesInfo> namespacesInfos = new ArrayList<>();
final Collection<String> includedInSwcNamespaces = builder.getIncludedNamespaces();
for (Pair<String, String> namespaceAndManifest : builder.getNamespacesAndManifests()) {
namespacesInfos.add(new NamespacesInfo(namespaceAndManifest.first, namespaceAndManifest.second, includedInSwcNamespaces.contains(namespaceAndManifest.first)));
}
data = Pair.create(currentTimestamp, namespacesInfos);
configFile.putUserData(MOD_STAMP_TO_NAMESPACES_INFOS, data);
} catch (IOException ignored) {
}
}
return data == null ? Collections.emptyList() : data.second;
}
use of com.intellij.util.text.CharSequenceReader in project intellij-community by JetBrains.
the class BaseExternalAnnotationsManager method getDataFromFile.
@NotNull
MostlySingularMultiMap<String, AnnotationData> getDataFromFile(@NotNull PsiFile file) {
Pair<MostlySingularMultiMap<String, AnnotationData>, Long> cached = myAnnotationFileToDataAndModStampCache.get(file);
long fileModificationStamp = file.getModificationStamp();
if (cached != null && cached.getSecond() == fileModificationStamp) {
return cached.getFirst();
}
DataParsingSaxHandler handler = new DataParsingSaxHandler(file);
try {
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
saxParser.parse(new InputSource(new CharSequenceReader(escapeAttributes(file.getViewProvider().getContents()))), handler);
} catch (IOException e) {
LOG.error(e);
} catch (ParserConfigurationException e) {
LOG.error(e);
} catch (SAXException e) {
LOG.error(e);
}
MostlySingularMultiMap<String, AnnotationData> result = handler.getResult();
myAnnotationFileToDataAndModStampCache.put(file, Pair.create(result, fileModificationStamp));
return result;
}
use of com.intellij.util.text.CharSequenceReader in project intellij-community by JetBrains.
the class PythonFileType method getCharsetFromEncodingDeclaration.
@Nullable
private static String getCharsetFromEncodingDeclaration(@Nullable CharSequence content) {
if (content == null || content.length() == 0) {
return null;
}
try {
final BufferedReader reader = new BufferedReader(new CharSequenceReader(content));
try {
for (int i = 0; i < MAX_CHARSET_ENCODING_LINE; i++) {
final String line = reader.readLine();
if (line == null) {
return null;
}
final Matcher matcher = ENCODING_PATTERN.matcher(line);
if (matcher.find()) {
final String charset = matcher.group(1);
return normalizeCharset(charset);
}
}
} finally {
reader.close();
}
} catch (IOException ignored) {
}
return null;
}
Aggregations