Sunday, July 26, 2015

Income Tax Calculation in India 2014-15

A good website describing the calculation with example is as follows: Learn-how-to-calculate-your-income-tax

An example calculation with an annual income of Rs 12,00,000.00 (where the income spans over all the three tax slabs), is shown below:

Slab
Income Slab (Rs.)
Income Tax Rate
Income Tax
Income Tax Amount
0
0 to 2,50,000
NIL
0
0
I
2,50,001-5,00,000
10%
10% of 2,50,000
25,000
II
5,00,001-10,00,000
20%
20% of 5,00,000
10,00,00
III
10,00,001 and above
30%
30% of (12,00,000 – 10,00,000)
= 30% of 2,00,000
60,000
Total Income Tax Amount
1,85,000
 
 Explanation:
If your income falls in Slab I, tax will be deducted on the amount that exceeds Rs. 2,50,001/- . Similarly, tax for Slab II and Slab III will be calculated for the amount that exceeds Rs. 5,00,001/- and Rs. 10,00,001/- respectively.

If the income lies above Slab III, then the tax in Slab I is calculated as 10% of (5,00,000 - 2,50,000) and tax in Slab II is calculated as 20% of (10,00,000 - 5,00,000). And the tax Slab III is calculated as 30% of (Annual Income - 10,00,000).

Wednesday, July 22, 2015

How to set the debug console buffer limit in Eclipse

  1. Click on Window -> Preferences
  2. In type filter text box, search for "Console"
  3. Select Console under Run/Debug
  4. For setting a limit, check the "Limit Console Output" check-box, and set the character limit in "Console buffer size (characters)" text box.
  5. For setting the Console buffer size to unlimited, uncheck the "Limit Console Output" check-box.

Wednesday, July 1, 2015

Java code to read and write objects in AWS S3


import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Date;
import org.apache.log4j.Logger;
import amazon.odin.awsauth.OdinAWSCredentialsProvider;
import com.amazonaws.HttpMethod;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.amazonaws.services.s3.model.S3Object;

public class S3Utils {
 public static final String MATERIAL_SET = "<material_set_name>";
 public static final String BUCKET = "<bucket_name>";
 public static final Integer S3_URL_VALIDITY_PERIOD_MILLISEC = 1000*60*60; // S3 url should be valid for 1 hour.
 private static final Logger logger = Logger.getLogger(S3Utils.class);
 private static final String folder = "<folder_name>";
 
 public static String writeToS3(File file, String folder) {
  com.amazonaws.services.s3.AmazonS3 s3Client = new com.amazonaws.services.s3.AmazonS3Client(
    getAWSCredentials());
  String key = file.getName();
  System.out.println("Going to write to key " + folder + key + " in S3");
  s3Client.putObject(BUCKET, folder + key, file);
  
  //This generates a URL that can be used to download the uploaded file.
  Date expiration = new Date();
  long msec = expiration.getTime();
  msec += S3_URL_VALIDITY_PERIOD_MILLISEC;
  expiration.setTime(msec);
  GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(BUCKET, folder + key);
  generatePresignedUrlRequest.setMethod(HttpMethod.GET);
  generatePresignedUrlRequest.setExpiration(expiration);
  URL s = s3Client.generatePresignedUrl(generatePresignedUrlRequest);
  if(s == null) {
   System.out.println("Url returned was null");
   return null;
  }
  System.out.println("S3 Url: " + s.toString());
  return s.toString();
 }
 
 public static String readFromS3(String folder, String key) {
  StringBuilder sb = new StringBuilder();
  com.amazonaws.services.s3.AmazonS3 s3Client = new com.amazonaws.services.s3.AmazonS3Client(
    getAWSCredentials());
  
  S3Object s3object = s3Client.getObject(BUCKET, folder + key);
  InputStream is = s3object.getObjectContent();
  BufferedReader br = new BufferedReader(new InputStreamReader(is));
  
  String line;
  try {
   while((line = br.readLine()) != null) {
    System.out.println(line);
    sb.append(line);
   }
  } catch (IOException e) {
   e.printStackTrace();
  }
  return sb.toString();
 }
 
 private static AWSCredentials getAWSCredentials() {
  AWSCredentialsProvider credentialsProvider = new OdinAWSCredentialsProvider(MATERIAL_SET);
     AWSCredentials credentials = credentialsProvider.getCredentials();
        return credentials;
    }
}