Search in sources :

Example 1 with CharSequenceReader

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));
}
Also used : CharSequenceReader(com.intellij.util.text.CharSequenceReader) JsonReader(com.google.gson.stream.JsonReader) JsonToken(com.google.gson.stream.JsonToken) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CharSequenceReader

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();
}
Also used : CharSequenceReader(com.intellij.util.text.CharSequenceReader) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CharSequenceReader

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;
}
Also used : FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) CharSequenceReader(com.intellij.util.text.CharSequenceReader)

Example 4 with CharSequenceReader

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;
}
Also used : InputSource(org.xml.sax.InputSource) MostlySingularMultiMap(com.intellij.util.containers.MostlySingularMultiMap) ConcurrentMostlySingularMultiMap(com.intellij.util.containers.ConcurrentMostlySingularMultiMap) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) CharSequenceReader(com.intellij.util.text.CharSequenceReader) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CharSequenceReader

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;
}
Also used : CharSequenceReader(com.intellij.util.text.CharSequenceReader) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

CharSequenceReader (com.intellij.util.text.CharSequenceReader)5 IOException (java.io.IOException)3 NotNull (org.jetbrains.annotations.NotNull)3 JsonReader (com.google.gson.stream.JsonReader)1 JsonToken (com.google.gson.stream.JsonToken)1 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 ConcurrentMostlySingularMultiMap (com.intellij.util.containers.ConcurrentMostlySingularMultiMap)1 MostlySingularMultiMap (com.intellij.util.containers.MostlySingularMultiMap)1 BufferedReader (java.io.BufferedReader)1 Matcher (java.util.regex.Matcher)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParser (javax.xml.parsers.SAXParser)1 Nullable (org.jetbrains.annotations.Nullable)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1