package com.nagaraju; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class ObjectSize { public static void main(String[] args) { checkStringResponseSize("Nagaraju",10); } public static void checkStringResponseSize(String list, Integer theGivenSize) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream objOut; Integer sizeOfData = 20; try { objOut = new ObjectOutputStream(baos); objOut.writeObject(list); Integer value = baos.toByteArray().length; if (theGivenSize != null && theGivenSize.intValue() != 0) { if (value > theGivenSize.intValue()) System.out.println("Response Size is Over from the given size."); } else if (value > sizeOfData.intValue()){ System.out.println("Response Size is Over from the defaul size."); }else{ System.out.println("Response Size is :"+value); } objOut.close(); } catch (IOException e) { System.out.println("IOException Occured"); } } }
Output: Response Size is Over from the given size.
No comments:
Post a Comment