• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java StreamUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.openapi.util.io.StreamUtil的典型用法代码示例。如果您正苦于以下问题:Java StreamUtil类的具体用法?Java StreamUtil怎么用?Java StreamUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StreamUtil类属于com.intellij.openapi.util.io包,在下文中一共展示了StreamUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: sendHtmlResponse

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
private void sendHtmlResponse(@NotNull HttpRequest request, @NotNull ChannelHandlerContext context, String pagePath) throws IOException {
  BufferExposingByteArrayOutputStream byteOut = new BufferExposingByteArrayOutputStream();
  InputStream pageTemplateStream = getClass().getResourceAsStream(pagePath);
  String pageTemplate = StreamUtil.readText(pageTemplateStream, Charset.forName("UTF-8"));
  try {
    String pageWithProductName = pageTemplate.replaceAll("%IDE_NAME", ApplicationNamesInfo.getInstance().getFullProductName());
    byteOut.write(StreamUtil.loadFromStream(new ByteArrayInputStream(pageWithProductName.getBytes(Charset.forName("UTF-8")))));
    HttpResponse response = Responses.response("text/html", Unpooled.wrappedBuffer(byteOut.getInternalBuffer(), 0, byteOut.size()));
    Responses.addNoCache(response);
    response.headers().set("X-Frame-Options", "Deny");
    Responses.send(response, context.channel(), request);
  }
  finally {
    byteOut.close();
    pageTemplateStream.close();
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:18,代码来源:EduStepikRestService.java


示例2: run

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
@Override
public void run() {
    try {
        logger.info("Attempting to read template main sketch file.");

        InputStream templateFileStream = this.getClass().getResourceAsStream("SketchTemplate.java.template");

        byte[] templateContent = StreamUtil.loadFromStream(templateFileStream);

        logger.info("Read a total of " + templateContent.length + " bytes from template sketch file stream.");

        VirtualFile sketchFile = sourceDirPointer.createChildData(this, "Sketch.java");

        logger.info("Attempting to create template sketch file '" + sketchFile + "' as a child of '" + sourceDirPointer.getPath() + "'.");

        try (OutputStream sketchFileStream = sketchFile.getOutputStream(ApplicationManager.getApplication())) {
            sketchFileStream.write(templateContent);
        }
    } catch (IOException ex) {
        logger.error(ex);
    }
}
 
开发者ID:mistodev,项目名称:processing-idea,代码行数:23,代码来源:CreateSketchTemplateFile.java


示例3: readClasspathResource

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
@Nullable
private String readClasspathResource(String name) {
    try {
        String classpath = System.getProperty("java.class.path");
        LOGGER.debug("Reading " + name + " from classpath=" + classpath);
        ClassLoader classLoader = OptionReference.class.getClassLoader();
        if (classLoader == null) {
            throw new IllegalStateException("Can not obtain classloader instance");
        }
        InputStream resource = classLoader.getResourceAsStream(name);
        if (resource == null) {
            LOGGER.debug("Could not find " + name);
            return null;
        }
        return StreamUtil.readText(resource, StandardCharsets.UTF_8);
    } catch (Exception e) {
        LOGGER.error("Could not read " + name, e);
    }
    return null;
}
 
开发者ID:protostuff,项目名称:protobuf-jetbrains-plugin,代码行数:21,代码来源:BundledFileProviderImpl.java


示例4: readFile

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
/**
 *
 * @param path String
 * @return String
 */
private String readFile(String path)
{
    String content = "";

    try {
        content = StreamUtil.readText(
                PhpClassRenderer.class.getResourceAsStream(path),
                "UTF-8"
        );
    } catch (IOException e) {
        e.printStackTrace();
    }

    return content;
}
 
开发者ID:project-a,项目名称:idea-php-spryker-plugin,代码行数:21,代码来源:PhpClassRenderer.java


示例5: readEntry

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
@Nullable
String readEntry(@NotNull final String endsWith) {
  try {
    return processStream(new StreamProcessor<String>() {
      @Override
      public String consume(@NotNull ZipInputStream stream) throws IOException {
        ZipEntry entry;
        while ((entry = stream.getNextEntry()) != null) {
          if (entry.getName().endsWith(endsWith)) {
            return StreamUtil.readText(stream, CharsetToolkit.UTF8_CHARSET);
          }
        }
        return null;
      }
    });
  }
  catch (IOException ignored) {
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:LocalArchivedTemplate.java


示例6: getTextForFlavor

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
@Nullable
public String getTextForFlavor(DataFlavor flavor) {
  if (myTexts.containsKey(flavor)) {
    return myTexts.get(flavor);
  }

  try {
    String text = StreamUtil.readTextFrom(flavor.getReaderForText(myTransferable));
    myTexts.put(flavor, text);
    return text;
  }
  catch (Exception e) {
    myTexts.put(flavor, null);
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:DnDNativeTarget.java


示例7: internalReadStream

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
private BufferExposingByteArrayOutputStream internalReadStream(int record) throws IOException {
  waitForPendingWriteForRecord(record);
  byte[] result;

  synchronized (myLock) {
    result = super.readBytes(record);
  }

  InflaterInputStream in = new CustomInflaterInputStream(result);
  try {
    final BufferExposingByteArrayOutputStream outputStream = new BufferExposingByteArrayOutputStream();
    StreamUtil.copyStreamContent(in, outputStream);
    return outputStream;
  }
  finally {
    in.close();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:RefCountingStorage.java


示例8: copyWithFiltering

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
private static void copyWithFiltering(File file, Ref<File> outputFileRef, List<ResourceRootFilter> filters, CompileContext context)
  throws IOException {
  final FileInputStream originalInputStream = new FileInputStream(file);
  try {
    final InputStream inputStream = transform(filters, originalInputStream, outputFileRef, context);
    FileUtil.createIfDoesntExist(outputFileRef.get());
    FileOutputStream outputStream = new FileOutputStream(outputFileRef.get());
    try {
      FileUtil.copy(inputStream, outputStream);
    }
    finally {
      StreamUtil.closeStream(inputStream);
      StreamUtil.closeStream(outputStream);
    }
  }
  finally {
    StreamUtil.closeStream(originalInputStream);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:GradleResourceFileProcessor.java


示例9: save

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
public void save(@NotNull ExternalProject externalProject) {
  Output output = null;
  try {
    final File externalProjectDir = externalProject.getProjectDir();
    final File configurationFile =
      getProjectConfigurationFile(new ProjectSystemId(externalProject.getExternalSystemId()), externalProjectDir);
    if (!FileUtil.createParentDirs(configurationFile)) return;

    output = new Output(new FileOutputStream(configurationFile));
    myKryo.writeObject(output, externalProject);

    LOG.debug("Data saved for imported project from: " + externalProjectDir.getPath());
  }
  catch (FileNotFoundException e) {
    LOG.error(e);
  }
  finally {
    StreamUtil.closeStream(output);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:ExternalProjectSerializer.java


示例10: load

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
@Nullable
public ExternalProject load(@NotNull ProjectSystemId externalSystemId, File externalProjectPath) {
  LOG.debug("Attempt to load project data from: " + externalProjectPath);
  ExternalProject externalProject = null;
  Input input = null;
  try {
    final File configurationFile = getProjectConfigurationFile(externalSystemId, externalProjectPath);
    if (configurationFile.isFile()) {
      input = new Input(new FileInputStream(configurationFile));
      externalProject = myKryo.readObject(input, DefaultExternalProject.class);
    }
  }
  catch (Exception e) {
    LOG.error(e);
  }
  finally {
    StreamUtil.closeStream(input);
  }

  if (externalProject != null) {
    LOG.debug("Loaded project: " + externalProject.getProjectDir());
  }
  return externalProject;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ExternalProjectSerializer.java


示例11: executeMethod

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
private String executeMethod(HttpMethod method) throws Exception {
  String responseBody;
  getHttpClient().executeMethod(method);
  Header contentType = method.getResponseHeader("Content-Type");
  if (contentType != null && contentType.getValue().contains("charset")) {
    // ISO-8859-1 if charset wasn't specified in response
    responseBody = StringUtil.notNullize(method.getResponseBodyAsString());
  }
  else {
    InputStream stream = method.getResponseBodyAsStream();
    responseBody = stream == null ? "" : StreamUtil.readText(stream, CharsetToolkit.UTF8_CHARSET);
  }
  if (method.getStatusCode() != HttpStatus.SC_OK) {
    throw new Exception("Request failed with HTTP error: " + method.getStatusText());
  }
  return responseBody;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GenericRepository.java


示例12: getResponseContentAsString

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
public static String getResponseContentAsString(@NotNull HttpMethod response) throws IOException {
  // Sometimes servers don't specify encoding and HttpMethod#getResponseBodyAsString
  // by default decodes from Latin-1, so we got to read byte stream and decode it from UTF-8
  // manually
  //if (!response.hasBeenUsed()) {
  //  return "";
  //}
  org.apache.commons.httpclient.Header header = response.getResponseHeader(HTTP.CONTENT_TYPE);
  if (header != null && header.getValue().contains("charset")) {
    // ISO-8859-1 if charset wasn't specified in response
    return StringUtil.notNullize(response.getResponseBodyAsString());
  }
  else {
    InputStream stream = response.getResponseBodyAsStream();
    return stream == null ? "" : StreamUtil.readText(stream, DEFAULT_CHARSET);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:TaskResponseUtil.java


示例13: splitLines

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
private static String[] splitLines(String string) {
  string = StreamUtil.convertSeparators(string);

  boolean spaceAdded = false;
  if (string.endsWith("\n")) {
    string += " ";
    spaceAdded = true;
  }

  final String[] temp = string.split("\n");

  if (spaceAdded) {
    final String[] result = new String[temp.length - 1];
    System.arraycopy(temp, 0, result, 0, result.length);
    return result;
  } else {
    return temp;
  }
}
 
开发者ID:Microsoft,项目名称:vso-intellij,代码行数:20,代码来源:AnnotationBuilder.java


示例14: readEntry

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
@Nullable
String readEntry(Condition<ZipEntry> condition) {
  ZipInputStream stream = null;
  try {
    stream = getStream();
    ZipEntry entry;
    while ((entry = stream.getNextEntry()) != null) {
      if (condition.value(entry)) {
        return StreamUtil.readText(stream, TemplateModuleBuilder.UTF_8);
      }
    }
  }
  catch (IOException e) {
    return null;
  }
  finally {
    StreamUtil.closeStream(stream);
  }
  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:LocalArchivedTemplate.java


示例15: getTemplates

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
private static MultiMap<String, ArchivedProjectTemplate> getTemplates() {
  InputStream stream = null;
  HttpURLConnection connection = null;
  String code = ApplicationInfo.getInstance().getBuild().getProductCode();
  try {
    connection = getConnection(code + "_templates.xml");
    stream = connection.getInputStream();
    String text = StreamUtil.readText(stream, TemplateModuleBuilder.UTF_8);
    return createFromText(text);
  }
  catch (IOException ex) {  // timeouts, lost connection etc
    LOG.info(ex);
    return MultiMap.emptyInstance();
  }
  catch (Exception e) {
    LOG.error(e);
    return MultiMap.emptyInstance();
  }
  finally {
    StreamUtil.closeStream(stream);
    if (connection != null) {
      connection.disconnect();
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:RemoteTemplatesFactory.java


示例16: internalReadStream

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
private BufferExposingByteArrayOutputStream internalReadStream(int record) throws IOException {
  waitForPendingWriteForRecord(record);

  synchronized (myLock) {

    byte[] result = super.readBytes(record);
    InflaterInputStream in = new CustomInflaterInputStream(result);
    try {
      final BufferExposingByteArrayOutputStream outputStream = new BufferExposingByteArrayOutputStream();
      StreamUtil.copyStreamContent(in, outputStream);
      return outputStream;
    }
    finally {
      in.close();
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:RefCountingStorage.java


示例17: makeRequest

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
/**
 * Make GET request to specified URL and return HTTP entity of result as Reader object
 */
private String makeRequest(String url) throws IOException {
  HttpClient client = getHttpClient();
  HttpMethod method = new GetMethod(url);
  configureHttpMethod(method);
  String entityContent;
  try {
    client.executeMethod(method);
    // Can't use HttpMethod#getResponseBodyAsString because Trello doesn't specify encoding
    // in Content-Type header and by default this method decodes from Latin-1
    entityContent = StreamUtil.readText(method.getResponseBodyAsStream(), "utf-8");
  }
  finally {
    method.releaseConnection();
  }
  LOG.debug(entityContent);
  //return new InputStreamReader(method.getResponseBodyAsStream(), "utf-8");
  return entityContent;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:TrelloRepository.java


示例18: build

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
@Override
public void build(@NotNull Project project, @NotNull Collection<FileObject> fileObjects) {
    Map<String, Route> routeMap = new HashMap<>();

    for (FileObject file : fileObjects) {

        String content;
        try {
            content = StreamUtil.readText(file.getContent().getInputStream(), "UTF-8");
        } catch (IOException e) {
            continue;
        }

        if(StringUtils.isBlank(content)) {
            continue;
        }

        routeMap.putAll(RouteHelper.getRoutesInsideUrlGeneratorFile(
            PhpPsiElementFactory.createPsiFileFromText(project, content)
        ));
    }

    this.routeMap = routeMap;
}
 
开发者ID:Haehnchen,项目名称:idea-php-symfony2-plugin,代码行数:25,代码来源:RoutingRemoteFileStorage.java


示例19: createEntityRepositoryContent

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
@Nullable
public static String createEntityRepositoryContent(Map<String, String> templateVars) {
    String content;

    try {
        content = StreamUtil.readText(CreateEntityRepositoryIntentionAction.class.getResourceAsStream("template/EntityRepository.php"), "UTF-8");
    } catch (IOException e) {
        return null;
    }

    for(Map.Entry<String, String> templateVar: templateVars.entrySet()) {
        content = content.replace("{{" + templateVar.getKey() +"}}", templateVar.getValue());
    }

    return content;
}
 
开发者ID:Haehnchen,项目名称:idea-php-annotation-plugin,代码行数:17,代码来源:CreateEntityRepositoryIntentionAction.java


示例20: runManagerCommand

import com.intellij.openapi.util.io.StreamUtil; //导入依赖的package包/类
private static boolean runManagerCommand(final String managerUrl) {
  try {
    URL url = new URL(managerUrl);
    long time = System.currentTimeMillis();
    while (System.currentTimeMillis() - time < TIMEOUT) {
      LOG.debug("Running server command: " + managerUrl);
      URLConnection urlConnection = url.openConnection();
      urlConnection.setDoInput(true);
      urlConnection.setDoOutput(false);
      String encoded = Base64.getEncoder().encodeToString(AUTHORIZATION_STRING.getBytes(StandardCharsets.UTF_8));
      urlConnection.setRequestProperty(AUTHORIZATION_PROPERTY, BASIC_AUTHORIZATION_METHOD + encoded);
      urlConnection.connect();
      String msg = StreamUtil.readText(urlConnection.getInputStream());
      LOG.debug("Server returned: " + msg);
      if (msg != null) {
        return !msg.startsWith(FAIL_MESSAGE_PREFIX);
      }
    }
    return false;
  } catch (IOException e) {
    LOG.debug(e);
    return false;
  }
}
 
开发者ID:consulo,项目名称:consulo-javaee,代码行数:25,代码来源:Tomcat4Deployer.java



注:本文中的com.intellij.openapi.util.io.StreamUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EntityManagerFactoryUtils类代码示例发布时间:2022-05-21
下一篇:
Java ArrayListSet类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap