当前位置: 首页>>代码示例>>Java>>正文


Java StringWriter.close方法代码示例

本文整理汇总了Java中java.io.StringWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java StringWriter.close方法的具体用法?Java StringWriter.close怎么用?Java StringWriter.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.StringWriter的用法示例。


在下文中一共展示了StringWriter.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: inputStreamToString

import java.io.StringWriter; //导入方法依赖的package包/类
/**
 * Using a Reader and a Writer, returns a String from an InputStream.
 */
public static String inputStreamToString(InputStream x,
        int length) throws IOException {

    InputStreamReader in        = new InputStreamReader(x);
    StringWriter      writer    = new StringWriter();
    int               blocksize = 8 * 1024;
    char[]            buffer    = new char[blocksize];

    for (int left = length; left > 0; ) {
        int read = in.read(buffer, 0, left > blocksize ? blocksize
                                                       : left);

        if (read == -1) {
            break;
        }

        writer.write(buffer, 0, read);

        left -= read;
    }

    writer.close();

    return writer.toString();
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:29,代码来源:StringConverter.java

示例2: dumpRegionServerMetrics

import java.io.StringWriter; //导入方法依赖的package包/类
/**
 * Dump out a subset of regionserver mbeans only, not all of them, as json on System.out.
 * @throws MalformedObjectNameException
 * @throws IOException
 */
public static String dumpRegionServerMetrics() throws MalformedObjectNameException, IOException {
  StringWriter sw = new StringWriter(1024 * 100); // Guess this size
  try (PrintWriter writer = new PrintWriter(sw)) {
    JSONBean dumper = new JSONBean();
    try (JSONBean.Writer jsonBeanWriter = dumper.open(writer)) {
      MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
      jsonBeanWriter.write(mbeanServer,
        new ObjectName("java.lang:type=Memory"), null, false);
      jsonBeanWriter.write(mbeanServer,
        new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=IPC"), null, false);
      jsonBeanWriter.write(mbeanServer,
        new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Replication"), null, false);
      jsonBeanWriter.write(mbeanServer,
        new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Server"), null, false);
    }
  }
  sw.close();
  return sw.toString();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:25,代码来源:JSONBean.java

示例3: treeToString

import java.io.StringWriter; //导入方法依赖的package包/类
public static String treeToString(TreeDocumentRoot doc) throws IOException {

        StringWriter out = new StringWriter();
        TreeStreamResult result = new TreeStreamResult(out);
        TreeWriter writer = result.getWriter(doc);

        try {
            writer.writeDocument();
            return out.toString();
        } catch (TreeException ex) {
            throw new IOException("Cannot read tree " +  ex.getMessage()); // NOI18N

        } finally {
            try {
                out.close();
            } catch (IOException ioex) {
                // do not know
            }
        }

    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TAXUtil.java

示例4: inputStreamToString

import java.io.StringWriter; //导入方法依赖的package包/类
/**
 * Using a Reader and a Writer, returns a String from an InputStream.
 *
 * Method based on Hypersonic Code
 *
 * @param x InputStream to read from
 * @throws IOException
 * @return a Java string
 */
public static String inputStreamToString(InputStream x,
        String encoding) throws IOException {

    InputStreamReader in        = new InputStreamReader(x, encoding);
    StringWriter      writer    = new StringWriter();
    int               blocksize = 8 * 1024;
    char[]            buffer    = new char[blocksize];

    for (;;) {
        int read = in.read(buffer);

        if (read == -1) {
            break;
        }

        writer.write(buffer, 0, read);
    }

    writer.close();

    return writer.toString();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:32,代码来源:StringConverter.java

示例5: downloadString

import java.io.StringWriter; //导入方法依赖的package包/类
public String downloadString() {
	try {
		StringWriter writer = new StringWriter();
		for (int i = this.responseStream.read(); i >= 0; i = this.responseStream.read())
			writer.write(i);

		String ret = writer.toString();

		writer.close();
		return ret;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:15,代码来源:HttpClient.java

示例6: getJSFileFromURL

import java.io.StringWriter; //导入方法依赖的package包/类
private String getJSFileFromURL(URLConnection paramURLConnection)
		throws Exception {
	// Trace.msgNetPrintln("net.proxy.auto.download.js", new Object[] {
	// paramURLConnection.getURL() });
	try {
		// RemoveCommentReader localRemoveCommentReader = new
		// RemoveCommentReader(new
		// InputStreamReader(paramURLConnection.getInputStream()));
		InputStreamReader localRemoveCommentReader = new InputStreamReader(
				paramURLConnection.getInputStream());
		BufferedReader localBufferedReader = new BufferedReader(
				localRemoveCommentReader);
		StringWriter localStringWriter = new StringWriter();
		char[] arrayOfChar = new char[100];
		int i;
		while ((i = localBufferedReader.read(arrayOfChar)) != -1) {
			localStringWriter.write(arrayOfChar, 0, i);
		}
		localBufferedReader.close();
		localRemoveCommentReader.close();
		localStringWriter.close();
		return localStringWriter.toString();
	} catch (Throwable localThrowable) {
		throw new Exception("Unable to obtain auto proxy file from "
				+ paramURLConnection.getURL(), localThrowable);
	}
}
 
开发者ID:kmarius,项目名称:xdman,代码行数:28,代码来源:AbstractAutoProxyHandler.java

示例7: testOpenBufferedStream

import java.io.StringWriter; //导入方法依赖的package包/类
public void testOpenBufferedStream() throws IOException {
  BufferedReader reader = source.openBufferedStream();

  StringWriter writer = new StringWriter();
  char[] buf = new char[64];
  int read;
  while ((read = reader.read(buf)) != -1) {
    writer.write(buf, 0, read);
  }
  reader.close();
  writer.close();

  assertExpectedString(writer.toString());
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:15,代码来源:CharSourceTester.java

示例8: json

import java.io.StringWriter; //导入方法依赖的package包/类
/**
 * json string.
 * 
 * @param obj object.
 * @param properties property name array.
 * @return json string.
 * @throws IOException.
 */
public static String json(Object obj, String[] properties) throws IOException
{
	if( obj == null ) return NULL;
	StringWriter sw = new StringWriter();
	try
	{
		json(obj, properties, sw);
		return sw.getBuffer().toString();
	}
	finally{ sw.close(); }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:20,代码来源:JSON.java

示例9: testOpenStream

import java.io.StringWriter; //导入方法依赖的package包/类
public void testOpenStream() throws IOException {
  Reader reader = source.openStream();

  StringWriter writer = new StringWriter();
  char[] buf = new char[64];
  int read;
  while ((read = reader.read(buf)) != -1) {
    writer.write(buf, 0, read);
  }
  reader.close();
  writer.close();

  assertExpectedString(writer.toString());
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:15,代码来源:CharSourceTester.java

示例10: getSOAPEnvelopeAsDocument

import java.io.StringWriter; //导入方法依赖的package包/类
private Document getSOAPEnvelopeAsDocument(SOAPEnvelope env, MessageContext msgContext)
        throws Exception {
    StringWriter writer = new StringWriter();
    SerializationContext serializeContext = new SerializationContext(writer, msgContext);
    env.output(serializeContext);
    writer.close();

    Reader reader = new StringReader(writer.getBuffer().toString());
    Document doc = XMLUtils.newDocument(new InputSource(reader));
    if (doc == null)
        throw new Exception(
                Messages.getMessage("noDoc00", writer.getBuffer().toString()));
    return doc;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:15,代码来源:SignedSOAPEnvelope.java

示例11: read

import java.io.StringWriter; //导入方法依赖的package包/类
/**
 * read string.
 * 
 * @param reader Reader instance.
 * @return String.
 * @throws IOException
 */
public static String read(Reader reader) throws IOException
{
	StringWriter writer = new StringWriter();
	try
	{
		write(reader, writer);
		return writer.getBuffer().toString();
	}
	finally{ writer.close(); }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:18,代码来源:IOUtils.java

示例12: createControlContent

import java.io.StringWriter; //导入方法依赖的package包/类
protected ContentProvider createControlContent () throws IOException
{
    this.packageControlFile.set ( BinaryPackageControlFile.Fields.INSTALLED_SIZE, "" + this.installedSize );

    final StringWriter sw = new StringWriter ();
    try ( ControlFileWriter writer = new ControlFileWriter ( sw ) )
    {
        this.packageControlFile.write ( writer );
    }
    sw.close ();

    return new StaticContentProvider ( sw.toString () );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:14,代码来源:DebianPackageWriter.java

示例13: LogMessage

import java.io.StringWriter; //导入方法依赖的package包/类
/**
 *  Constructs an instance from a Log4J event, using the specified layout.
 *
 *  @throws RuntimeException if any error occurred during formatting or conversion.
 *          Will include any root cause other than UnsupportedEncodingException.
 */
public LogMessage(LoggingEvent event, Layout layout)
{
    try
    {
        StringWriter out = new StringWriter(1024);
        out.write(layout.format(event));
        if ((event.getThrowableInformation() != null) && layout.ignoresThrowable())
        {
            for (String traceline : event.getThrowableStrRep())
            {
                out.write(traceline);
                out.write(Layout.LINE_SEP);
            }
        }
        out.close();

        this.timestamp = event.getTimeStamp();
        this.message = out.toString();
        this.messageBytes = this.message.getBytes("UTF-8");
    }
    catch (UnsupportedEncodingException e)
    {
        throw new RuntimeException("UnsupportedEncodingException when converting to UTF-8");
    }
    catch (Exception ex)
    {
        throw new RuntimeException("error creating LogMessage", ex);
    }
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:36,代码来源:LogMessage.java

示例14: sendException

import java.io.StringWriter; //导入方法依赖的package包/类
public static void sendException(@Nullable IUser author, @Nullable String message, Exception e, Class clazz) {
	if (Main.getSelfUser() != null) {
		IUser bot = Main.getSelfUser();
		EmbedBuilder em = new EmbedBuilder();
		if (bot != null) {
			em.withAuthorIcon(bot.getAvatarURL());
		}
		if (author != null) {
			em.withAuthorName(author.getName());
			em.withThumbnail(author.getAvatarURL());
		}
		em.withColor(239, 15, 0);
		em.withFooterText(clazz.getName());

		String timeStamp = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss").format(Calendar.getInstance().getTime());
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		e.printStackTrace(pw);
		String error = sw.toString(); // stack trace as a string
		if (error.length() > 1250) {
			error = error.substring(0, 1250);
		}
		pw.close();

		try {
			sw.close();
		} catch (IOException e1) {
			//Can ignore silently...
		}


		em.appendField("Time", timeStamp, true);
		if (e.getMessage() != null) {
			if (e.getMessage().length() > 1024) {
				em.appendField("Exception", e.getMessage().substring(0, 1024), true);
			} else {
				em.appendField("Exception", e.getMessage(), true);
			}
		}
		if (message != null) {
			em.appendField("Message", message, true);
		}

		//Get DisCal guild and channel..
		IGuild guild = Main.client.getGuildByID(266063520112574464L);
		IChannel channel = guild.getChannelByID(302249332244217856L);

		Message.sendMessage(em.build(), "```" + error + "```", channel);
	} else {
		//TODO: Add to log file...
	}
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:53,代码来源:ExceptionHandler.java

示例15: refresh

import java.io.StringWriter; //导入方法依赖的package包/类
private void refresh() {
    final TextView resultView = (TextView) findViewById(R.id.sendResults);
    for (TransactionLogEntry transactionLogEntry : demoAppDB.getLogEntries(lastTimestamp)) {
        StringBuilder stringBuilder = new StringBuilder(LINE_SEPARATOR);
        stringBuilder.append("[");
        stringBuilder.append(simpleDateFormat.format(transactionLogEntry.getCreated()));
        stringBuilder.append("] - ");

        TransactionResult transactionResult = transactionLogEntry.getTransactionResult();
        if (transactionResult != null) {
            if (transactionResult.getFlowFilesSent() < 0) {
                stringBuilder.append(transactionResult.getMessage());
            } else {
                stringBuilder.append("Sent ");
                stringBuilder.append(transactionResult.getFlowFilesSent());
                stringBuilder.append(" flow file(s) and received response \"");
                stringBuilder.append(transactionResult.getResponseCode());
                stringBuilder.append("\"");
            }
        } else {
            IOException ioException = transactionLogEntry.getIoException();
            if (ioException != null) {
                StringWriter stringWriter = new StringWriter();
                try {
                    PrintWriter printWriter = new PrintWriter(stringWriter);
                    try {
                        ioException.printStackTrace(printWriter);
                    } finally {
                        printWriter.close();
                    }
                } finally {
                    try {
                        stringWriter.close();
                    } catch (IOException e) {
                        //Ignore
                    }
                }
                stringBuilder.append(stringWriter);
            } else {
                stringBuilder.append("Error, no transaction result or exception");
            }
        }
        stringBuilder.append(LINE_SEPARATOR);
        lastTimestamp = Math.max(lastTimestamp, transactionLogEntry.getCreated().getTime());
        resultView.append(stringBuilder.toString());
    }
}
 
开发者ID:hortonworks,项目名称:nifi-android-s2s,代码行数:48,代码来源:MainActivity.java


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