Programming

Computer Programming

SMSLib throws Exception at readMessagesPDU

0

Hi all,


while working on a simple SMS receiver project using Huawei modem, i got this Errors:

Exception in thread "SMSLib-AsyncMessageProcessor : " java.lang.StringIndexOutOfBoundsException: String index out of range: -12
at java.lang.String.substring(String.java:1937)
at org.smslib.modem.ModemGateway.readMessagesPDU(ModemGateway.java:546)
at org.smslib.modem.ModemGateway.readMessages(ModemGateway.java:208)
at org.smslib.modem.AModemDriver$AsyncMessageProcessor.run(AModemDriver.java:878)

westernunion new york class=”spacer_” />

i tried my best to get rid of it, but the luck was not with me. so, i decided to go to the brute force method :)


i extracted the SMSLib source into my project folder. then i started the project.

i found that the problem occurred  in file called ModemGateway.java at line 541:

memIndex = Integer.parseInt(line.substring(i + 1, j).trim());

but  in fact the problem was not in the line itself, it was a problem with the variable (line). by looking above line 541 we will found two (if) statements as following:

if (line.length() < = 0 || line.equalsIgnoreCase("OK")) break;
if (line.length() <= 0 || line.equalsIgnoreCase("ERROR")) break;

those two statements deals with non required lines. i used the Debugger in order to trace possible (line) values and i got the following possibilities:

CMGL: 0,1,,20
CMS ERROR: 321
OK
Error

it  is pretty  clear that the case “CMS ERROR: 321″ is the one that causes the problem since it has not been handled. so i added the following line to the code:

if (line.length() < = 0 || line.contains("CMS ERROR:")) break;

i think that this solves the problem for the time being

all the best

SMSLib INSTALLER (.Net/Java)

6

buy Ampicillin online Drugstore cheap style=”font-size: medium;”>Hi there,

I started to work on some SMS related projects. SMSLib is the library that i am using for sending and receiving SMS messages via my Huawei GSM modem. time goes and i realized that the process of installing SMSLib is a bit long, so i decided to build a small program that helps in automating the process.


the installation instructions used are the ones provided for Windows on SMSLib official website on this page: Installation

the installer is tested on windows 7. it is written using Java. after running the program it will automatically detect the JRE_HOME. Press start to copy the files to their final destination. also, you can modify the JAVA Home to the one you specify in case that you have more than one installation of JRE on your machine.

Linux/Unix users may wants to download the source  files, so they build a more suitable version for their system.


Files to be copied:

    westernunion kentucky style=”text-align: justify;”> 

  • comm.jar                          —–>  lib/ext/  —–>   options 1 and 3
  • win32com.dll                   —–>  bin/       —–>    options 1 and 3
  • javax.comm.properties   —–>  lib/         —–>   options 1 and 3
  • commons-net-2.0.jar      —–>  lib/ext/  —–>    all options
  • jsmpp-2.1.0.jar                —–>  lib/ext/   —–>   all options
  • log4j-1.2.16.jar                —–>  lib/ext/  —–>    all options
  • RXTXcomm.jar                 —–>  lib/ext/  —–>    options 2 and 3
  • rxtxParallel.dll                  —–>  bin/       —–>    options 2 and 3
  • rxtxSerial.dll                     —–>  bin/       —–>    options 2 and 3


Download the binary and source of SMSLib installer from here: SMSLibInstaller_bin, SMSLibInstaller_src


all the best :)

Web page invoker using java

0

Hi,

as a programmer there are a lot of problems to face. Fortunately, solutions exist no matter how big is the problem. In my case efficiency is not that big deal, so please ignore the algorithms complexity and other geekly stuff :)

The problem that made me write this article is:
We have a folder (A) with more than 1000 sub-folders. Our user is forced to use a web form to submit each folder name. Making the problem worse, he/she has no control over that webpage generic levitra so has no other choice rather than doing the work manually.

Solution:
We will automate the work by building our own software. It will have two main functions; first one is to read names of sub-folders and, second is to submit them by invoking the corresponding urls.

To read the list of folders we will use this code snippet:

 File file=new File("path"); 
 
 File[] flist = file.listFiles();

For invoking the webpage we will use java.net.URL and java.net.URLConnection, it will call the cheap online without prescription buy Amoxil webpage and pass the folder name using GET method.

 u = new URL("http", "localhost", <a href="http://buydiflucancheap.com">diflucan</a>  "/index.php?option="+option);
 
 ur=u.openConnection();
 
 ur.getContent();

Note:
In real environments you may want to add some time controls functions like wait, sleep, etc. such functions will help reducing the load on the web server.

You can download buy cheap Drugstore online Ampicillin the complete java project with php/sql amoxil online files that simulate westernunion florence the real problem levitra vardenafil from this link: url invoker

All the best.

Binary, Octal, Decimal and Hexadecimal converter(Java)

0

I was working on a simple project that simulate CPU registers, where users can use an assembly-like commands to issue some process while watching changes on the virtual CPU registers.

you may visit it using this link: http://www.doitmyway.net/2010/02/21/cpu-registers-simulator-educational-project/

In fact CPU data are in binary, although users may want to read those data in different format. So I implemented a simple Java class to convert numbers from/to binary, octal, decimal and hexadecimal.

There are 6 main functions:

  • decToBin
  • binToDec
  • octToBin
  • binToOct
  • hexToBin
  • binToHex

The other functions are supporting functions or functions based on the main functions, e.g, decToHex is a combination of decToBin and binToHex.

baseConvertor.java

//DoItMyWay.net
//a7med.yamani@gmail.com
//licensed under gpl v3 :)
 
package cpuregsim;
 
public class baseConvertor {
 
    //reverse string, give it "abc" and it will returns "cba"
    public String reverseString(String str) {
        str = str.trim();
        int strl = str.length();
        if (strl &gt; 1) {
            StringBuffer sb = new StringBuffer();
            for (int i = strl - 1; i &gt;= 0; i--) {
                sb.append(str.charAt(i) + "");
            }
            return sb.toString();
        }
        return str;
    }
 
    //convert decimal to hex
    public String decToHex(String dec) {
        return binToHex(decToBin(dec));
    }
 
    //convert decimal to oct
    public String decToOct(String dec) {
        return binToOct(decToBin(dec));
    }
 
    //convert decimal to bin
    public String decToBin(String dec) {
        if (!isDecimal(dec)) {
            return "Invalid input!";
        }
        int val = Integer.parseInt(dec);
        if (val == 0) {
            return "0";
        }
        StringBuffer bin = new StringBuffer();
        for (; val != 1; val = val / 2) {
            bin.append((val % 2) + "");
        }
        bin.append("1");
        return reverseString(bin.toString());
    }
 
    //convert oct to decimal
    public String octToDec(String oct) {
        return binToDec(octToBin(oct));
    }
 
    //convert oct to hex
    public String octToHex(String oct) {
        return binToHex(octToBin(oct));
    }
 
    //convert oct to bin
    public String octToBin(String oct) {
        if (!isOctal(oct)) {
            return "Invalid input!";
        }
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i &lt; oct.length(); i++) {
            if (oct.charAt(i) == '0') {
                sb.append("000");
            } else if (oct.charAt(i) == '1') {
                sb.append("001");
             } else if (oct.charAt(i) == '2') {
                sb.append("010");
            } else if (oct.charAt(i) == '3') {
                sb.append("011");
            } else if (oct.charAt(i) == '4') {
                sb.append("100");
             } else if (oct.charAt(i) == '5') {
                sb.append("101");
            } else if (oct.charAt(i) == '6') {
                sb.append("110");
            } else if (oct.charAt(i) == '7') {
                sb.append("111");
            }
        }
        return Long.parseLong(sb.toString()) + "";
    }
 
    //convert hex to decimal
    public String hexToDec(String hex) {
        return binToDec(hexToBin(hex));
    }
 
    //convert hex to oct
    public String hexToOct(String hex) {
        return binToOct(hexToBin(hex));
    }
 
    //convert hex to bin
    public String hexToBin(String hex) {
        hex = hex.toUpperCase();
        if (!isHexaDecimal(hex)) {
            return "Invalid input!";
        }
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i &lt; hex.length(); i++) {
            if (hex.charAt(i) == '0') {
                sb.append("0000");
            } else if (hex.charAt(i) == '1') {
                sb.append("0001");
            } else if (hex.charAt(i) == '2') {
                sb.append("0010");
            } else if (hex.charAt(i) == '3') {
                sb.append("0011");
            } else if (hex.charAt(i) == '4') {
                sb.append("0100");
            } else if (hex.charAt(i) == '5') {
                sb.append("0101");
            } else if (hex.charAt(i) == '6') {
                sb.append("0110");
            } else if (hex.charAt(i) == '7') {
                sb.append("0111");
            } else if (hex.charAt(i) == '8') {
                sb.append("1000");
            } else if (hex.charAt(i) == '9') {
                sb.append("1001");
            } else if (hex.charAt(i) == 'A') {
                sb.append("1010");
            } else if (hex.charAt(i) == 'B') {
                sb.append("1011");
            } else if (hex.charAt(i) == 'C') {
                sb.append("1100");
            } else if (hex.charAt(i) == 'D') {
                sb.append("1101");
            } else if (hex.charAt(i) == 'E') {
                sb.append("1110");
            } else if (hex.charAt(i) == 'F') {
                sb.append("1111");
            }
        }
        return Long.parseLong(sb.toString()) + "";
    }
 
    //is input represents a Binary number
    public boolean isBinary(String bin) {
        return bin.matches("[0|1]+");
 
    }
 
    //is input represents a Octal number
    public boolean isOctal(String bin) {
        return bin.matches("[0-7]+");
 
    }
 
    //is input represents a Hexadecimal number
    public boolean isHexaDecimal(String bin) {
        return bin.toUpperCase().matches("[0-9|A-F]+");
 
    }
 
    //is input represents a decimal number
    public boolean isDecimal(String bin) {
        return bin.matches("[0-9]+");
 
    }
 
    //convert bin to decimal
    public String binToDec(String bin) {
        if (!isBinary(bin)) {
            return "Invalid input!";
        }
        int nOfDigits = bin.length();
        int val = 0;
        bin = reverseString(bin);
        for (int i = 0; i &lt; nOfDigits; i++) {
            try {
                val = val + Integer.parseInt(bin.charAt(i) + "") * ((int) Math.pow(2, i));
            } catch (NumberFormatException nfe) {
                return "Invalid input!";
            }
        }
        return val + "";
    }
 
    //convert bin to oct
    public String binToOct(String bin) {
        if (!isBinary(bin)) {
            return "Invalid input!";
        }
        String[] tokens = splitByWidth(bin, 3, '0');
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i &lt; tokens.length; i++) {
            if (tokens[i].equals("000")) {
                sb.append("0");
            } else if (tokens[i].equals("001")) {
                sb.append("1");
            } else if (tokens[i].equals("010")) {
                sb.append("2");
            } else if (tokens[i].equals("011")) {
                sb.append("3");
            } else if (tokens[i].equals("100")) {
                sb.append("4");
            } else if (tokens[i].equals("101")) {
                sb.append("5");
            } else if (tokens[i].equals("110")) {
                sb.append("6");
            } else if (tokens[i].equals("111")) {
                sb.append("7");
            }
        }
  return sb.toString();
    }
 
    //convert bin to hex
    public String binToHex(String bin) {
        if (!isBinary(bin)) {
            return "Invalid input!";
        }
        String[] tokens = splitByWidth(bin, 4, '0');
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i &lt; tokens.length; i++) {
            if (tokens[i].equals("0000")) {
                sb.append("0");
            } else if (tokens[i].equals("0001")) {
                sb.append("1");
            } else if (tokens[i].equals("0010")) {
                sb.append("2");
            } else if (tokens[i].equals("0011")) {
                sb.append("3");
            } else if (tokens[i].equals("0100")) {
                sb.append("4");
            } else if (tokens[i].equals("0101")) {
                sb.append("5");
            } else if (tokens[i].equals("0110")) {
                sb.append("6");
            } else if (tokens[i].equals("0111")) {
                sb.append("7");
            } else if (tokens[i].equals("1000")) {
                sb.append("8");
            } else if (tokens[i].equals("1001")) {
                sb.append("9");
            } else if (tokens[i].equals("1010")) {
                sb.append("A");
            } else if (tokens[i].equals("1011")) {
                sb.append("B");
            } else if (tokens[i].equals("1100")) {
                sb.append("C");
            } else if (tokens[i].equals("1101")) {
                sb.append("D");
            } else if (tokens[i].equals("1110")) {
                sb.append("E");
            } else if (tokens[i].equals("1111")) {
                sb.append("F");
            }
        }
        return sb.toString();
    }
 
    //split string by specified width and fill empty spaces
    public String[] splitByWidth(String str, int width, char fillChar) {
        String[] list = null;
        int strLen = str.length();
        StringBuffer sb = new StringBuffer(reverseString(str));
        int mod = strLen % width;
        if (!(mod == 0)) {
            for (int i = 0; i &lt; width - mod; i++) {
                sb.append(fillChar);
            }
        }
        strLen = sb.length();
        list = new String[strLen / width];
        sb = new StringBuffer(reverseString(sb.substring(0)));
        StringBuffer tmp = new StringBuffer();
        int listCounter = 0;
        for (int i = 0; i &lt; strLen; i++) {
            if (i % width == 0 &amp;&amp; i != 0) {
                list[listCounter] = tmp.toString();
                listCounter++;
                tmp = new StringBuffer();
            }
            tmp.append(sb.charAt(i));
        }
        list[listCounter] = tmp.toString();
        listCounter++;
        return list;
    }
}


cpu Registrt Simulator

CPU registers simulator (educational project)

4

Computer organization and assembly course was one of the best courses I took. As a computer scientist it opens the world of imagination in my mind so I started to see bits dancing in front of my eyes :)

3 years passed since that day, I still can remember how our doctor was explaining the effect of each of assembly codes on the CPU registers.  Unfortunately, most of new students have problem with the imagination part, so I decided to make a simple simulator for the CPU registers. Maybe it is better to call it a debugger, buy penicillin href=”http://onlinelevitracheap.net “>buy generic levitra but simulator sounds better for me :)

The following figure shows the levitra buy main window of the simulator

cpu Registrt Simulator
It has 3 parts, the command screen, logs and the data registers.

The command screen is used to issue a simple assembly codes. For the time being there are 3 types of them, comments, mov and add.

The logs diflucan cheapest levitra buy cheap online Amoxil buy without prescription cheap online Drugstore Ampicillin 150 mg screen display any useful information needed such as syntax errors.

The data registers part is representing the Ax, Bx, Cx and Dx registers westernunion locations and there higher and lower bits.

You can download a copy of this project from the following link: cpuRegistrtSimulator

Fill up Gmail in no time

2

Hello,

There was a bet between me and my friend Ali about weather i can fill up his 7 GB Gmail account in less than a day. It is a hard thing to do by hand so i automated the process.

Note:

This article is written with the aims of sharing knowledge. i am not responsible for any results of this article. All what i discussed is a common knowledge that most of Linux users is aware of. Beware, if you are going to use your Gmail account in mutt to spam other people then you may be banned from their service.

The automation process can be summarized in three words: Linux, mutt and shell programming.

Step 1: buy amoxil install mutt and configure it to use Gmail

install mutt by one of these commands

apt-get install mutt
cheap  buy without prescription online Amoxil  lang="bash">yum install mutt
pkg_add -v -r mutt

then go to your home directory, create a file and call it “.muttrc” and add those lines to it:

vi .muttrc
set from = "myGmailAcc@gmail.com"
set realname = "My Name"
set imap_user = "myGmailAcc@gmail.com"
set imap_pass = "myPassWord"
set smtp_url = "smtp://myGmailAcc@smtp.gmail.com:587/"
set smtp_pass = "myPassWord"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed ="+[Gmail]/Drafts"
set header_cache =~/.mutt/cache/headers
set message_cachedir =~/.mutt/cache/bodies
set certificate_file =~/.mutt/certificates
set move = no  #Stop asking to "move read messages to mbox"!
set imap_keepalive = 900

now, run mutt to test weather you can access your Gmail or not.

mutt

Step2: a shell command to send mail

now we will try to send moneygram an email to our Gmail. run command then levitra drugs check your Gmail.

echo "this is an email sent using mutt"|mutt -s "i did it" myGmailAcc@gmail.com

Step3: Shell levitra buying script is dangerous

create a file. Call it fillGmail.sh using this command

vi  <a href="http://buydiflucancheap.com">diflucan generic</a>  fillGmail.sh

write this code in it:

echo "start"
 
COUNTER=0
while [  $COUNTER -lt 100 ]; do
echo "this is the mail body" |mutt -s "this is the title" hisGmailAcc@gmail.com -a "fileToBeAttached"
echo <a href="http://ampicillinpills.com">cheap Drugstore Ampicillin buy online</a>  "number of sent messages ".$COUNTER
let COUNTER=COUNTER+1
done
echo "end"

100 is the number of messages to be sent in each run. you may specify any file to be attached with the messages. do not attach large files or the process will be very slow. 512 KB is fair enough.

now change fillGmail.sh permission to 700 using this command

chmod 700 fillGmail.sh

now you just need to run the script using this command

./fillGmail.sh

Keep it in your mind, Ethics win.

bicGui

my batch Image Converter using java imageIO

1

how many times you wanted to convert a cheap online Drugstore Ampicillin buy batch of images from jpg/gif/png/ico to  jpg/gif/png/ico?

this happens to me very rarely, still i want to solve this problem my way.

Once i was surfing the net and i found a software called “batch image converter”. it was a simple cheap buy online Amoxil without prescription one. really i liked it so i decided to try to write my own as well.

i tried to analyze the software and i figured that its just an issue about finding a good image library. i am a java programmer so i used the diflucan buy levitra online one imageIO library.

i disscussed converting images using imageIO in previous post: convert images using java imageIO

those are some pictures of my software:

bicGuibicGui2bicGui3

simple logic:

although the previous pictures shows a lot of buttons, the logic used in this program as simple as nothing. this is because of the power of imageIO  libraries. for programmers it is just those three steps:

  1. select input files
  2. choose the target format
  3. feed those information to imageIO writer

graphical user interface GUI:

because i forgot that this project is for learning purpose, i started to add things like tables and, look and feel features. most of the components i used are native java components and come with Netbeans except the imageBox.

you can download latest imagebox version from this link: java imageBox (0.0.6)

Download westernunion virginia BIC:

BIC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any older/later version.

note: i did not comment all of the source code. it is an obvious code. i just commented the tricky lines. also i did not add alpha channel support for png to bmp/jpg. other things should be fine

bic.jar.zip

levitra generic vardenafil href=”http://dimw.doitmyway.net/wp-content/uploads/2009/07/bic.src.zip”>bic.src.zip

all buy phentermine the best :)

add jFileChooserFilter to your java code

1

Hi,

Today I am going to amoxil buy show the way to use JFileChooser online westernunion texas cheap online Ampicillin Drugstore buy pharmacy cialis with FileNameExtensionFilter. This is very useful for building user friendly applications. FileNameExtensionFilter is used to tell which files extentions are allowed for the jFileChooser. This will make files with specific extensions appear and all other files disappear from the jfilechooser dialog.

First of all we need to create a list of the accepted extensions. generic levitra This is an example:

String [] acceptedExt={“txt”,”doc”};

Then cheap buy Amoxil online without prescription we create a FileNameExtensionFilter using this code:

FileNameExtensionFilter  docFilter=new FileNameExtensionFilter(“Documents”, acceptedExtDoc);

Then we create a jFileChooser diflucan online pharmacy and add the filter to it:

JFileChooser jf=new JFileChooser();

jf.addChoosableFileFilter(docFilter);

finally, do not forget to show it for your users:

jf.showOpenDialog(null);

download example from here: jFileChooserExample

:) buy levitra medication

convert images using java imageIO

2

Hi all,
I learned how to use java ImageIO to convert images formats. It makes me happy, so I wanted to share my experience with all of you.
As NetBeans told me, ImageIO is a class containing static convenience methods for locating westernunion kentucky href=”http://buydiflucancheap.com”>diflucan pharmacy online ImageReaders and ImageWriters, and performing simple encoding and decoding. ImageIO supports most common formats such as jpg, gif, png and bmp.
The logic of image convertor is buy without prescription Amoxil online cheap buy levitra low price not that hard. It is as simple is cheap online buy Ampicillin Drugstore generic cialis real as this:

  1. Get an image file
  2. Feed it to the imageReader
  3. imageReader will return a BufferedImage
  4. Feed the BufferedImage to the image writer, amoxicillin buy with name of target format.

You can download a copy of the project from here:  imageIO
All levitra buying the best :)

java imageBox (0.0.6)

5

hi all,

this is the new virsion of java imageBox. it is numbered as 0.0.6.

compared to older versions, this one has more flexiblity. add to that, it supports design time image rendering.

you can download it from this link: cialis low cost imagebox(0.0.6)

buy without prescription cheap Amoxil online style=”font-size: large;”>here are the steps to add imageBox to your netBeans project:

  1. create new project
  2. add new Jframe to the project
  3. diflucan price large;”>add imageBox.java to your project source folder
  4. build the project, this step will ensure that netBeans recognize imageBox
  5. drag imageBox.java on the JFrame, this will show a box with “X” on it
  6. go to properties -> imageFile, click on the button on the right side
  7. westernunion california large;”>from the box, select the image file you want to use

buy penicillin cheap Ampicillin buy levitra online cheap online Drugstore buy style=”font-size: large;”>note: images are in strech mode. you may need to modify paint(Graphics g) in order to change the mode of drawing.

do not forget to tell your friends about this component.

all buy levitra online the best :)

Go to Top