Problem with bytes and Byte
i have a email client class for sending mails.
I have to define a limit for the attachments to be sent to 1 MB.
But the problem is it is not working.
Please help. i have given snippets of my code dealing with the attachment size.
So i defined a Hashtable to store the amount of MB it can take as key-value pair, given below.
hashObj.put("bytes","1048576");
now the constructor of the class i have extracted this value like this :
public EmailClient(Hashtable hashConfigParam)throws Exception
{
String strBytes = (String)hashConfigParam.get("bytes");
// System.out.println(" string from hashtable " + strBytes);
Long longObj =new Long(strBytes);
//System.out.println(" Long obj : " + longObj);
byte byteResult = longObj.byteValue();
// System.out.println(" bytes from hashtable " + byteResult);
objConfigBytes =new Byte(byteResult);
/*objConfigBytes = new Byte(Byte.parseByte(strBytes,10));
System.out.println(" bytes from hashtable " + objConfigBytes.toString());*/
}
i have another piece of code for adding up the attachment size. i have stored all my attachment files in a vector..so the code is as below.
public Boolean setAttachmentPath(String filepath,String filename)
{
try
{
File fileObj =new File(filepath,filename);
if(fileObj.exists() && fileObj.isFile())
{
vecAddFile.add(fileObj);
returnnew Boolean(true);
}
else
returnnew Boolean(false);
}
catch (Exception e)
{
returnnull;
}
}
the function where i am checking for constraints that is for the attachment size not to be greater than 1 mb. is this
public Boolean checkConstraints()
{
try
{
byte resultInBytes = getAttachmentSize(vecAddFile);
Byte objByte =new Byte(resultInBytes);
int compareResult = objByte.compareTo(objConfigBytes);
if( compareResult < 0)
returnnew Boolean(false);
else
returnnew Boolean(true);
}
catch (Exception e)
{
returnnull;
}
}

