java-io

Zip file created on server and download that zip, using java

。_饼干妹妹 提交于 2019-12-09 19:25:56
问题 I have the below code got from mkyong, to zip files on local. But, my requirement is to zip files on server and need to download that. Could any one help. code wrote to zipFiles: public void zipFiles(File contentFile, File navFile) { byte[] buffer = new byte[1024]; try{ // i dont have idea on what to give here in fileoutputstream FileOutputStream fos = new FileOutputStream("C:\\MyFile.zip"); ZipOutputStream zos = new ZipOutputStream(fos); ZipEntry ze= new ZipEntry(contentFile.toString()); zos

Java (J2SE) DTMF tone detection

谁都会走 提交于 2019-12-09 07:12:41
问题 I am trying to do the following I am getting a call to another person using my java application (Already done & works fine). Then I am playing a recording, for example "Please press 1 one to continue in english" (Already done & works fine). Now I want to detect that person press one, As per my researches in google search I got that this can do using DTMF.If the person press 1 I want to do the actions according to my condition. My question is how to detect that number using DTMF in java (J2SE)

Array classes with serialVersionUID?

那年仲夏 提交于 2019-12-08 20:04:24
I am having trouble understanding this comment from the Java serialization documentation : Array classes cannot declare an explicit serialVersionUID, so they always have the default computed value, but the requirement for matching serialVersionUID values is waived for array classes. Maybe I am unable to understand the obvious, however, I haven't figured why would I need to do this? Paul Wagland I think that the answer to your question is to read up on serialVersionUID . In particular, you often want to specify this on your classes to be able to deal with the fact that classes change over time.

REST CXF and Spring cxf-extension-jaxrs-binding File not found exception?

主宰稳场 提交于 2019-12-08 17:32:33
问题 i'm trynig to develop a REST web service using CXF 2.6.0 and spring 2.5.6 my CXF maven dependancy in the pom.xml are : <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-rs-extension-providers</artifactId> <version>2.6.0</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-rs-extension-search</artifactId> <version>2.6.0</version> </dependency> I'am using Spring 2.5.6 and i have declared my web service in the applicationcontext.xml spring

Reading a text file & adding the content to an ArrayList

久未见 提交于 2019-12-08 13:46:52
问题 I am learning about all of the different ways to take input from a text file and read through the content. I am struggling to use a try - catch block (with resources), and reading in the file name. Below is what I have written for this part so far:- public static void main(String[] args) { ArrayList<StationRecord> data = new ArrayList<>(); String stationName = null; Scanner scan = new Scanner(System.in); System.out.println("What is the filename?"); String input = scan.nextLine(); File file =

Looping over byte channels

徘徊边缘 提交于 2019-12-08 11:15:15
问题 While reading from the good-old InputStream , I used the following code(with which I was never comfortable) : int read = 0; InputStream is = ....; while((i = is.read() != -1){ .... } Now I'm trying to read 10MB from an InputStream using NIO : protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub System.out.println("In Controller.doPost(...)"); ByteBuffer chunk = ByteBuffer.allocateDirect

converting outputStream to byte array [duplicate]

假装没事ソ 提交于 2019-12-08 04:55:47
问题 This question already has answers here : How to convert outputStream to a byte array? (4 answers) Closed 2 years ago . How can I get the bytes of an outputStream, or how can I convert an outputStream to a byte array? 回答1: From a theoretical perspective (i.e., irrespective of whether it makes sense in practice as a use case), this is an interesting question that essentially requires the implementation of a method like public abstract byte[] convert(OutputStream out); The Java OutputStream

base64 decoded file is not equal to the original unencoded file

匆匆过客 提交于 2019-12-08 02:06:14
问题 I have a normal pdf file A.pdf , a third party encodes the file in base64 and sends it to me in a webservice as a long string (i have no control on the third party). My problem is that when i decode the string with java org.apache.commons.codec.binary.Base64 and right the output to a file called B.pdf I expect B.pdf to be identical to A.pdf, but B.pdf turns out a little different then A.pdf. As a result B.pdf is not recognized as a valid pdf by acrobat. Does base64 have different types of

stitch images together in java

↘锁芯ラ 提交于 2019-12-07 12:25:28
问题 I'm trying to stitch some images together using java. I have a bunch of images I'd like to stitch together and they are all the same dimensions so it's really just a question of lining them up next to each other I suppose. I have it working but it's very slow and probably very memory intensive. I'm wondering if there's an easier way: public static void main(String[] args) throws IOException { int dim = 256; BufferedImage merged = null; for(int y = 0; y<10;y++) { for(int x = 0; x<10;x++) { URL

Java I/O - Simulate input for System.console()

无人久伴 提交于 2019-12-07 07:18:07
问题 I am writing a JUnit for a program created in an exercise. That means the test needs to cover as many cases as possible and I don't have any influence on how certain things in the program are implemented. Also, the program runs an infinite loop where at one point, it requires the user to input something. For the JUnit test I run the program in another Thread and simulate the user input from within the JUnit Thread . So far, everything works fine if the program reads the user input from System