<% %><%@ page import="java.io.*" %><%@ page import="java.net.*" %><%@ page import="java.util.*" %><%@ page import="mmmmllll.hk.aws2.quotation.util.QuotationWebKeys" %><%@ page import="mmmmllll.hk.aws2.master.util.AwsResourceReader" %><%@ page import="mmmmllll.common.framework.util.GenericResourceReader" %><%@ page import="mmmmllll.common.framework.security.CipherObject" %><%@ page import="mmmmllll.common.util.Logger" %><%! public static void copyFile(InputStream in, OutputStream out) throws IOException { try { byte[] buf = new byte[4096]; int i = 0; while ((i = in.read(buf)) != -1) { out.write(buf, 0, i); } } catch (IOException e) { e.printStackTrace(); throw e; } finally { try { in.close(); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } } } %><% String quotationFileDownloadServerPath = AwsResourceReader.in.getSafeString("QuotationPdfFileDownloadServer.path"); String filePath = ""; String[] parameters = (String[]) session.getAttribute(QuotationWebKeys.QUOTATION_PRINT_PARAMETERS); /* * parameters[0] - quotation owner key * parameters[1] - quotation number * parameters[2] - filename * parameters[3] - generateFlag 'Y' or 'N' * parameters[4] - optional param, generateFilePathFlag 'Y' or 'N'; */ String fileName = parameters[2]; String quotationNr = parameters[1]; String ownerKey = parameters[0]; String generateFlag = parameters[3]; String generateFilePathFlag = "N"; if (parameters.length == 5) { generateFilePathFlag = parameters[4]; } try{ GenericResourceReader reader = AwsResourceReader.in; String username = reader.getSafeString("FILE_DOWNLOAD_USERNAME"); String password = reader.getSafeString("FILE_DOWNLOAD_PASSWORD"); String isProduction = reader.getSafeString("FILE_DOWNLOAD_IS_PRODUCTION"); //filePath = reader.getSafeString("FILE_DOWNLOAD_QUOTATION_FOLDER_PATH"); String urlPath = quotationFileDownloadServerPath + "?file_name=" + fileName; System.out.println("Url Path = " + urlPath); // *** if isProduction, get and decrypt username and password from properities file. if (isProduction != null && isProduction.equalsIgnoreCase("true")) { String loginFilePath = reader.getSafeString("FILE_DOWNLOAD_LOGIN_FILE_PATH"); String keyFilePath = reader.getSafeString("FILE_DOWNLOAD_KEY_FILE_PATH"); String algorithm = reader.getSafeString("FILE_DOWNLOAD_CRYPT_ALGORITHM"); CipherObject c = CipherObject.getInstance(keyFilePath, algorithm); File file = new File(ora.ml.asup.util.WrappedFile.pathWrapper(loginFilePath)); FileInputStream fis = new FileInputStream(file); byte[] loginInfo = new byte[fis.available()]; fis.read(loginInfo); String loginInfoStr = new String(c.decrypt(loginInfo)); int semiColonPos = loginInfoStr.indexOf(';'); username = loginInfoStr.substring(0, semiColonPos); password = loginInfoStr.substring(semiColonPos + 1); fis.close(); } urlPath += "&username=" + username; urlPath += "&password=" + password; urlPath += ""ation_nr=" + quotationNr; urlPath += "&owner_key=" + ownerKey; urlPath += "&generate_flag=" + generateFlag; urlPath += "&generate_file_path_flag=" + generateFilePathFlag; System.out.println("Url Path = " + urlPath); Logger.logStat(this, "start " + quotationNr + " " + new Date()); URL url = new URL(urlPath); InputStream in = url.openStream(); //response.setContentType("application/pdf"); response.setContentType("application/postscript"); //response.setHeader("Content-disposition", "attachment; filename="+fileName ); ServletOutputStream ostream = response.getOutputStream(); copyFile(in,ostream); Logger.logStat(this, "end " + quotationNr + " " + new Date()); Logger.logStat("[ID=" + session.getId() + "] end...action=quotation_aw054_01_get_report"); response.flushBuffer(); } catch (Exception e){ Logger.logStat(this, "end " + quotationNr + " " + new Date() + " " + e); // *** if the username and password is invalid or any other exception throw in file server. *** response.setContentType("application/pdf"); //response.setHeader("Content-disposition", "attachment; filename=Error.txt"); out.print("The file server is temporary unavailable, please try again later."); } %>
相关推荐
关于InputStream和OutputStream关于InputStream和OutputStream关于InputStream和OutputStream关于InputStream和OutputStream
InputStream与OutputStream及File间互转
System.out.println("文件不存在...."); } else { try { InputStream is = new FileInputStream(file1);// 打开文件 byte[] cont = new byte[(int) file1.length()]; is.read(cont);// 读取文件...
NULL 博文链接:https://shihuan830619.iteye.com/blog/2094068
IO流文档,相关IO流的说明文档.............
当你还是一个java初学者的时候,是不是还在为你没有一个好的源代码模仿去学习而烦恼,这个代码很容易看懂,对你学习很有帮助
Java SE程序 文件的拷贝InputStream类Java SE程序 文件的拷贝InputStream类Java SE程序 文件的拷贝InputStream类Java SE程序 文件的拷贝InputStream类Java SE程序 文件的拷贝InputStream类Java SE程序 文件的拷贝...
这是本人多年的积累,可是我的高手老师讲的!!口传心受呀,高手必看!呵呵
LowPoly.generate(inputStream,outputStream); 或者 /** * 生成low poly风格的图片 * * @param inputStream 源图片 * @param outputStream 输出图片流 * @param accuracy 精度值,越小精度越高 * @param scale...
使用最简单的InputStream输入流和OutputStream输出流,制作了文件之间的粘贴复制功能。程序已测试,可以把一个word文件中的内容完整复制到另一个word文件中。
NULL 博文链接:https://nethub2.iteye.com/blog/2023937
JAVA 文件读写操作 在 JDK 1.0 中,通常是用 InputStream & OutputStream 这两个基类来进行读写操作的。 InputStream 中的 FileInputStream 类似一个文件句柄,通过它来对文件进行操作
OutputStream out = socket.getOutputStream(); ObjectOutputStream objout = new ObjectOutputStream(out); // 向服务器发送信息 objout.writeObject(user); socket.shutdownOutput(); System....
springboot 解决InputStream只能读取一次的问题
流操作:使用Java的输入输出流(InputStream、OutputStream)来读取和写入文件内容。 异常处理:通过捕获并处理IOException等异常,确保程序在压缩和解压缩过程中的稳定性。 应用领域: Java文件压缩与解压缩实践...
简单叙述InputStream 和OutputStream 加上异常机制
实际上,除了实现DataInput和 DataOutput接口之外(DataInputStream和DataOutputStream也实现了这两个接口),它和这两个类系毫不相干,甚至不使用InputStream和OutputStream类中已经存在的任何功能;它是
InputStream in = lnew BufferedInputStream(new FileInputStream(name)); Properties p = new Properties(); p.load(in); 2。使用java.util.ResourceBundle类的getBundle()方法 示例: ResourceBundle rb ...
java各类IO流的整理demo,其内包含InputStream/OutputStream BufferedReader流 FileOutputStream/FileInputStream流 PrintWriter流 DataOut/DataIn流 Object流 FileChannel类;
Java中InputStream类.pdf 学习资料 复习资料 教学资源