本文整理汇总了Java中com.intellij.openapi.util.io.StreamUtil类的典型用法代码示例。如果您正苦于以下问题:Java StreamUtil类的具体用法?Java StreamUtil怎么用?Java StreamUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StreamUtil类属于com.intellij.openapi.util.io包,在下文中一共展示了StreamUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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();
}
}
}