Search in sources :

Example 21 with StringTokenizer

use of com.intellij.util.text.StringTokenizer in project intellij-community by JetBrains.

the class EncodingAwareProperties method load.

public void load(File file, String encoding) throws IOException {
    String propText = FileUtil.loadFile(file, encoding);
    propText = StringUtil.convertLineSeparators(propText);
    StringTokenizer stringTokenizer = new StringTokenizer(propText, "\n");
    while (stringTokenizer.hasMoreElements()) {
        String line = stringTokenizer.nextElement();
        int i = line.indexOf('=');
        String propName = i == -1 ? line : line.substring(0, i);
        String propValue = i == -1 ? "" : line.substring(i + 1);
        setProperty(propName, propValue);
    }
}
Also used : StringTokenizer(com.intellij.util.text.StringTokenizer)

Example 22 with StringTokenizer

use of com.intellij.util.text.StringTokenizer in project kotlin by JetBrains.

the class VfsTestUtil method createFileOrDir.

private static VirtualFile createFileOrDir(VirtualFile root, String relativePath, String text, boolean dir) {
    try {
        AccessToken token = WriteAction.start();
        try {
            VirtualFile parent = root;
            Assert.assertNotNull(parent);
            StringTokenizer parents = new StringTokenizer(PathUtil.getParentPath(relativePath), "/");
            while (parents.hasMoreTokens()) {
                String name = parents.nextToken();
                VirtualFile child = parent.findChild(name);
                if (child == null || !child.isValid()) {
                    child = parent.createChildDirectory(VfsTestUtil.class, name);
                }
                parent = child;
            }
            VirtualFile file;
            //need this to ensure that fileCreated event is fired
            parent.getChildren();
            if (dir) {
                file = parent.createChildDirectory(VfsTestUtil.class, PathUtil.getFileName(relativePath));
            } else {
                file = parent.findFileByRelativePath(relativePath);
                if (file == null) {
                    file = parent.createChildData(VfsTestUtil.class, PathUtil.getFileName(relativePath));
                }
                VfsUtil.saveText(file, text);
            }
            return file;
        } finally {
            token.finish();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StringTokenizer(com.intellij.util.text.StringTokenizer) AccessToken(com.intellij.openapi.application.AccessToken) IOException(java.io.IOException)

Example 23 with StringTokenizer

use of com.intellij.util.text.StringTokenizer in project android by JetBrains.

the class IdeTestApplication method addAdditionalClassPath.

private static void addAdditionalClassPath(@NotNull Collection<URL> classpath) throws MalformedURLException {
    StringTokenizer tokenizer = new StringTokenizer(System.getProperty(PROPERTY_ADDITIONAL_CLASSPATH, ""), File.pathSeparator, false);
    while (tokenizer.hasMoreTokens()) {
        String pathItem = tokenizer.nextToken();
        classpath.add(new File(pathItem).toURI().toURL());
    }
}
Also used : StringTokenizer(com.intellij.util.text.StringTokenizer) File(java.io.File)

Example 24 with StringTokenizer

use of com.intellij.util.text.StringTokenizer in project intellij-plugins by JetBrains.

the class ExternalTask method scheduleInputStreamReading.

protected void scheduleInputStreamReading() {
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        boolean usageStarted = false;
        final InputStreamReader reader = FlexCommonUtils.createInputStreamReader(myProcess.getInputStream());
        try {
            char[] buf = new char[4096];
            int read;
            while ((read = reader.read(buf, 0, buf.length)) >= 0) {
                final String output = new String(buf, 0, read);
                debug("Process output: " + output);
                if (!usageStarted) {
                    final StringTokenizer tokenizer = new StringTokenizer(output, "\r\n");
                    while (tokenizer.hasMoreElements()) {
                        final String message = tokenizer.nextElement();
                        if (!StringUtil.isEmptyOrSpaces(message)) {
                            if (message.trim().toLowerCase().startsWith("usage:")) {
                                usageStarted = true;
                                break;
                            }
                            if (message.trim().endsWith("password:")) {
                                final OutputStream outputStream = myProcess.getOutputStream();
                                outputStream.write("\n".getBytes());
                                outputStream.flush();
                            } else {
                                myMessages.add(message);
                            }
                        }
                    }
                }
            }
        } catch (IOException e) {
            myMessages.add(e.getMessage());
        } finally {
            cancel();
            try {
                reader.close();
            } catch (IOException e) {
            /*ignore*/
            }
        }
    });
}
Also used : StringTokenizer(com.intellij.util.text.StringTokenizer) InputStreamReader(java.io.InputStreamReader) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 25 with StringTokenizer

use of com.intellij.util.text.StringTokenizer in project intellij-plugins by JetBrains.

the class ASC20CompilationTask method readInputStream.

private void readInputStream(final FlexCompilationManager compilationManager) {
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final InputStreamReader reader = FlexCommonUtils.createInputStreamReader(myProcess.getInputStream());
        try {
            char[] buf = new char[2048];
            int read;
            while ((read = reader.read(buf, 0, buf.length)) >= 0) {
                final String output = new String(buf, 0, read);
                final StringTokenizer tokenizer = new StringTokenizer(output, "\r\n");
                while (tokenizer.hasMoreElements()) {
                    final String message = tokenizer.nextElement();
                    if (StringUtil.isEmptyOrSpaces(message))
                        continue;
                    final boolean ok = handleCompilerMessage(compilationManager, message.trim());
                    if (!ok) {
                        myCompilationFailed = true;
                    }
                }
            }
            printPreviousLine(compilationManager);
        } catch (IOException e) {
            compilationManager.addMessage(this, CompilerMessageCategory.ERROR, e.getMessage(), null, -1, -1);
            myCompilationFailed = true;
        } finally {
            cancel();
            try {
                reader.close();
            } catch (IOException e) {
            /*ignore*/
            }
        }
    });
}
Also used : StringTokenizer(com.intellij.util.text.StringTokenizer) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException)

Aggregations

StringTokenizer (com.intellij.util.text.StringTokenizer)25 File (java.io.File)5 IOException (java.io.IOException)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 TextRange (com.intellij.openapi.util.TextRange)2 PsiReference (com.intellij.psi.PsiReference)2 InputStreamReader (java.io.InputStreamReader)2 NonNls (org.jetbrains.annotations.NonNls)2 JavacOutputParser (com.intellij.compiler.impl.javaCompiler.javac.JavacOutputParser)1 ConsoleViewContentType (com.intellij.execution.ui.ConsoleViewContentType)1 Lexer (com.intellij.lexer.Lexer)1 AccessToken (com.intellij.openapi.application.AccessToken)1 CompilerMessageCategory (com.intellij.openapi.compiler.CompilerMessageCategory)1 Document (com.intellij.openapi.editor.Document)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 Problem (com.intellij.problems.Problem)1 WolfTheProblemSolver (com.intellij.problems.WolfTheProblemSolver)1