本文整理汇总了Java中java.io.PrintWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java PrintWriter.close方法的具体用法?Java PrintWriter.close怎么用?Java PrintWriter.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.PrintWriter
的用法示例。
在下文中一共展示了PrintWriter.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fixFaultySession
import java.io.PrintWriter; //导入方法依赖的package包/类
private ActionForward fixFaultySession(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws DokumaranConfigurationException, ServletException, IOException {
IDokumaranService service = getDokumaranService();
Long toolSessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID);
DokumaranSession session = service.getDokumaranSessionBySessionId(toolSessionId);
try {
log.debug("Fixing faulty session (sessionId=" + toolSessionId + ").");
service.createPad(session.getDokumaran(), session);
} catch (Exception e) {
// printing out error cause
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.write("Failed! " + e.getMessage());
out.flush();
out.close();
log.error("Failed! " + e.getMessage());
return null;
}
return null;
}
示例2: createFallbackPOM
import java.io.PrintWriter; //导入方法依赖的package包/类
private static synchronized File createFallbackPOM(String groupId, String artifactId, String version) throws IOException {
String k = groupId + ':' + artifactId + ':' + version;
File fallbackPOM = fallbackPOMs.get(k);
if (fallbackPOM == null) {
fallbackPOM = File.createTempFile("fallback", ".netbeans.pom");
fallbackPOM.deleteOnExit();
PrintWriter w = new PrintWriter(fallbackPOM);
try {
w.println("<project>");
w.println("<modelVersion>4.0.0</modelVersion>");
w.println("<groupId>" + groupId + "</groupId>");
w.println("<artifactId>" + artifactId + "</artifactId>");
w.println("<packaging>pom</packaging>");
w.println("<version>" + version + "</version>");
w.println("<name>" + FALLBACK_NAME + "</name>");
w.println("</project>");
w.flush();
} finally {
w.close();
}
fallbackPOMs.put(k, fallbackPOM);
}
return fallbackPOM;
}
示例3: save
import java.io.PrintWriter; //导入方法依赖的package包/类
public static final void save() throws IOException {
Console.print("Saving settings...", null);
final Properties properties = new Properties();
final File file = new File(Content.PREFERENCES_FILE);
if (!file.exists()) file.createNewFile();
final PrintWriter writer = new PrintWriter(file);
properties.setProperty("render_distance", RENDER_DISTANCE + "");
properties.setProperty("render_hand", RENDER_HAND + "");
properties.setProperty("render_clouds", RENDER_CLOUDS + "");
properties.setProperty("screen_width", SCREEN_WIDTH + "");
properties.setProperty("screen_height", SCREEN_HEIGHT + "");
properties.setProperty("minimap_size", MINIMAP_SIZE + "");
properties.setProperty("render_light_rays", RENDER_LIGHT_RAYS + "");
properties.setProperty("vsync", VSYNC + "");
properties.store(writer, "");
writer.close();
}
示例4: toStackTraceString
import java.io.PrintWriter; //导入方法依赖的package包/类
/**
* To stack trace string string.
* <p>
* 此方法参见:https://github.com/Ereza/CustomActivityOnCrash
*
* @param throwable the throwable
* @return the string
*/
public static String toStackTraceString(Throwable throwable) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
String stackTraceString = sw.toString();
//Reduce data to 128KB so we don't get a TransactionTooLargeException when sending the intent.
//The limit is 1MB on Android but some devices seem to have it lower.
//See: http://developer.android.com/reference/android/os/TransactionTooLargeException.html
//And: http://stackoverflow.com/questions/11451393/what-to-do-on-transactiontoolargeexception#comment46697371_12809171
if (stackTraceString.length() > MAX_STACK_TRACE_SIZE) {
String disclaimer = " [stack trace too large]";
stackTraceString = stackTraceString.substring(0, MAX_STACK_TRACE_SIZE - disclaimer.length()) + disclaimer;
}
pw.close();
return stackTraceString;
}
示例5: actionPerformed
import java.io.PrintWriter; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
try {
frame.chooser.setDialogTitle("Wybierz miejsce gdzie zapisać plik.");
int result = frame.chooser.showSaveDialog(null);
if (result != JFileChooser.APPROVE_OPTION){
return;
}
frame.to = frame.chooser.getSelectedFile();
PrintWriter pr = new PrintWriter(frame.to);
pr.println("n: "+ this.frame.bottom.settings.nTeeth.getSelectedItem());
pr.println("d[m]: "+ this.frame.bottom.settings.distance.getSelectedItem());
pr.println("w[rad/s] \t Q/Qmax");
for (int i=0; i<frame.bottom.graph.data.length ; i++)
{
if(frame.bottom.graph.data[i]>-1){
pr.println(i*5 + " \t " + frame.bottom.graph.data[i]/255.0);
}
}
pr.close();
}
catch (IOException ee) {
ee.printStackTrace();
}
}
示例6: addToFile
import java.io.PrintWriter; //导入方法依赖的package包/类
private void addToFile(String p, String address) throws IOException {
File f = new File(p);
f.createNewFile();
PrintWriter writer = new PrintWriter(new FileWriter(f, true));
try {
writer.println(address);
} finally {
writer.close();
}
}
示例7: dumpExceptionToSDCard
import java.io.PrintWriter; //导入方法依赖的package包/类
private void dumpExceptionToSDCard(Throwable ex) throws IOException {
/* 如果 SD 卡不存在或无法使用,则无法把异常信息写入 SD 卡 */
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
if (DEBUG) {
Log.w(TAG, "sdcard unmounted, skip dump exception");
return;
}
}
File dir = new File(PATH);
if (!dir.exists()) {
dir.mkdirs();
}
long current = System.currentTimeMillis();
String time = new SimpleDateFormat("yyy-MM-dd HH:mm:ss", Locale.CHINA).format(new Date(current));
File file = new File(PATH + FILE_NAME + time + FILE_NAME_SUFFIX);
try {
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
pw.println(time);
dumpPhoneInfo(pw);
pw.println();
ex.printStackTrace(pw);
pw.close();
} catch (Exception e) {
Log.e(TAG, "dump crash info failed");
}
}
示例8: hello
import java.io.PrintWriter; //导入方法依赖的package包/类
public void hello() throws IOException {
ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
PrintWriter out = ServletActionContext.getResponse().getWriter();
try {
out.print("TestStruts2Action hello()");
out.flush();
out.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
示例9: render
import java.io.PrintWriter; //导入方法依赖的package包/类
@Override
public void render(final HttpServletRequest request, final HttpServletResponse response) {
try {
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
final PrintWriter writer = response.getWriter();
writer.write(content);
writer.close();
} catch (final IOException e) {
logger.error("Render failed", e);
}
}
示例10: toString
import java.io.PrintWriter; //导入方法依赖的package包/类
public static String toString(Throwable e) {
StringWriter w = new StringWriter();
PrintWriter p = new PrintWriter(w);
p.print(e.getClass().getName() + ": ");
if (e.getMessage() != null) {
p.print(e.getMessage() + "\n");
}
p.println();
try {
e.printStackTrace(p);
return w.toString();
} finally {
p.close();
}
}
示例11: testCreateFunctionSetDir
import java.io.PrintWriter; //导入方法依赖的package包/类
@Test
public void testCreateFunctionSetDir() throws IOException {
createService(SERVICE_NAME);
// Create a function
CreateFunctionRequest createFuncReq = new CreateFunctionRequest(SERVICE_NAME);
createFuncReq.setFunctionName(FUNCTION_NAME);
createFuncReq.setDescription("Function for test");
createFuncReq.setMemorySize(128);
createFuncReq.setHandler("hello_world.handler");
createFuncReq.setRuntime("nodejs4.4");
// Setup code directory
String tmpDir = "/tmp/fc_test_" + UUID.randomUUID();
String funcFilePath = tmpDir + "/" + "hello_world.js";
new File(tmpDir).mkdir();
PrintWriter out = new PrintWriter(funcFilePath);
out.println(
"'use strict'; module.exports.handler = function(event, context, callback) {console.log('hello world'); callback(null, 'hello world');};");
out.close();
Code code = new Code().setDir(tmpDir);
createFuncReq.setCode(code);
createFuncReq.setTimeout(10);
client.createFunction(createFuncReq);
// Invoke the function
InvokeFunctionRequest request = new InvokeFunctionRequest(SERVICE_NAME, FUNCTION_NAME);
InvokeFunctionResponse response = client.invokeFunction(request);
assertEquals("hello world", new String(response.getPayload()));
// Cleanups
client.deleteFunction(new DeleteFunctionRequest(SERVICE_NAME, FUNCTION_NAME));
client.deleteService(new DeleteServiceRequest(SERVICE_NAME));
new File(funcFilePath).delete();
new File(tmpDir).delete();
}
示例12: buildExceptionMessage
import java.io.PrintWriter; //导入方法依赖的package包/类
private String buildExceptionMessage(Throwable throwable){
Throwable root=buildRootException(throwable);
StringWriter sw=new StringWriter();
PrintWriter pw=new PrintWriter(sw);
root.printStackTrace(pw);
String trace=sw.getBuffer().toString();
trace=trace.replaceAll("\n", "<br>");
pw.close();
return trace;
}
示例13: getAuthBody
import java.io.PrintWriter; //导入方法依赖的package包/类
private Buffer getAuthBody(final String user, final String password) {
final Map<String, String> values = new HashMap<String, String>();
values.put("username", user);
values.put("password", password);
// TODO: switch to File Callback?
final InputStream in = this.getClass().getResourceAsStream(Constants.AUTH_SOAP_TEMPLATE);
if (in == null) {
this.logger.error("Could not retrieve resource " + Constants.AUTH_SOAP_TEMPLATE);
return Buffer.buffer();
}
final Scanner scanner = new Scanner(in);
scanner.useDelimiter("\\Z");
final String authTemplate = scanner.next();
scanner.close();
final MustacheFactory mf = new DefaultMustacheFactory();
final Mustache mustache = mf.compile(new StringReader(authTemplate), "Login");
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final PrintWriter pw = new PrintWriter(out);
try {
mustache.execute(pw, values).flush();
pw.close();
} catch (final IOException e) {
this.logger.error(e);
return Buffer.buffer();
}
return Buffer.buffer(out.toByteArray());
}
示例14: SaveScore
import java.io.PrintWriter; //导入方法依赖的package包/类
public SaveScore(String nombreNuevo, int scoreNuevo){
try {
escribir = new PrintWriter(new BufferedWriter(new FileWriter("top10.txt", true)));
escribir.println(nombreNuevo+"-"+scoreNuevo);
escribir.close();
leer();
} catch (IOException ex) {
System.out.println("No se pudo registrar en el archivo");
}
}
示例15: execute
import java.io.PrintWriter; //导入方法依赖的package包/类
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method=retriveMethod(req);
if(method!=null){
invokeMethod(method, req, resp);
}else{
VelocityContext context = new VelocityContext();
context.put("contextPath", req.getContextPath());
resp.setContentType("text/html");
resp.setCharacterEncoding("utf-8");
Template template=ve.getTemplate("ureport-html/designer.html","utf-8");
PrintWriter writer=resp.getWriter();
template.merge(context, writer);
writer.close();
}
}