Posts

Showing posts with the label file

Image processing using SWT Image APIS

Eclipse SWT Image APIs provides great level of abstraction for all basic image processing operations like scaling , cropping etc.In this post I have provided code snippet to some of the most common image processing operations. There are main two classes in SWT ( org.eclipse.swt.graphics) Image API org.eclipse.swt.graphics.Image org.eclipse.swt.graphics.ImageData Instances of Image class are graphics which have been prepared for display on a specific device. Instances of ImageData class are device-independent descriptions of images. They are typically used as an intermediate format between loading from or writing to streams and creating an Image . Following code snippet shows creating Image reference as well as retrieving ImageData from image . /* creating Image reference using image path */ Image imageRef = new Image(Display.getCurrent(), "image.jpg" ); ImageData imageData = imageRef.getImageData(); //processing image data //.. //creating image using i...

Eclipse PDE: Everything about Editor

Image
Editors are the most important part of eclipse IDE framework. Editor are the primary framework to create and modify resource like files. Every eclipse plug-in or eclipse based products needs to provide custom editor for editing proprietary resources. I am tried to put important parts of Eclipse Editor Framework in this pos. This is the first post from the series "Everything About Editor" Everything about Editor Document Partition Syntax Highlighting Auto-Edit Strategy Code Completion using Content Assist Eclipse divides the concept of a text editor into two parts: the document and the viewer. While the document holds the actual content of the editor, the viewer is responsible for handling the content display. This nice Model-View-Controller (MVC)-style separation allows you to separate code that manipulates the content of the editor from the part that manipulates its display. The Document represents the "model" part of the text editor framework. It c...

FileVisitor from NIO.2 File System API in Java 7

As a part of project Coin ( Language changes ) in Java 7 improved version of file operation APIS has introduced, java.nio.file . There are many new functionalities has been introduced for ease of day to day programming, FileVisitor is one these APIs. As explained above, new interface java.nio.file.FileVisitor has been introduced for traversing the file system. It has methods like preVisitDirectory(), postVisitDirectory() , visitFile () etc to give control to programmer to do any specific task while traversing/visiting the file system. A concrete  implementation java.nio.file.SimpleFileVisitor has been provided those don't want to provide implementation for all of the methods from java.nio.file.FileVisitor . Here is simple example using these new classes.   package com.test.jdk7; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.att...

Downloading a file from web application

Image
      This post explains developing a web application which allows requestor to download a file. Here web app will have a servlet which streams requested file to requestor. follow the step to develop it using NetBean 6.8 1. Create a web application [ refer previous posts ] 2.Create a Servlet and add the code given below in doGet method      String filePath =null;      int length =0;        //accept file name as parameter         String fileName = request.getParameter("FILE_NAME");         InputStream is = getServletContext().getClassLoader().getResourceAsStream("/"+fileName);         if(is == null){             PrintWriter writer = response.getWriter();   ...