Nio Decoding problem

hi
i am using nio at server side.
from the client(normal socket) i am writing onto it using ObjectOutputStream.
oos.writeObject("DATA");
but at server it's coming with some junk value before the String. (t[][]DATA)
i am using us-ascii encoding.
any help is appreciated
Navin

In JDK 1.4 Object transfer isn't supported directly by NIO. The "junk" before the data describes the type of the object. You should be sending from the client using a byte or character oriented stream. If you use the OutputStreamWriter, it will send using the default encoding for your system.

Similar Messages

  • Problems with nio decoder need help plz

    I want to make a flash/php chat Client with Java Server with the new nio.
    Problem is to Convert a Bytebuffer into a normal string.
    I done this with the charsetdecoder and it works...
    if i give the string with system.println out it will be the right string. but i cant use the string with the if method..
    my source:
    php:
    $nick="Nerrik";
    $host = "localhost";
    $data="-".$nick.";$REMOTE_ADDR";
    $fp = fsockopen($host,1120);
    fwrite($fp, $data,strlen($data));
    fclose($fp);
    java:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.nio.*;
    import java.nio.channels.*;
    import java.nio.charset.*;
    public class newserver
    Charset charset = Charset.forName("ISO-8859-1");
    CharsetDecoder decoder = charset.newDecoder();
    CharsetEncoder encoder = charset.newEncoder();
    ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
    CharBuffer charBuffer = CharBuffer.allocate(1024);
    String[] user=new String[100];
    String[] user2=new String[100];
    private Selector readSelector;
    public void start() throws Exception
    System.out.println("Server Gestartet...");
    System.out.println("Protokoll aktiv");
    SocketChannel client;
    readSelector=Selector.open();
    ServerSocketChannel channel=ServerSocketChannel.open();
    ServerSocket socket=channel.socket();
    socket.bind(new InetSocketAddress ("localhost",1120));
    channel.configureBlocking(false);
    while (true)
    client=channel.accept();
    if (client!=null)
    client.configureBlocking(false);
    client.register(readSelector,SelectionKey.OP_READ);
    handleClientRequest();
    public void handleClientRequest() throws Exception
    Set keys;
    Iterator it;
    SelectionKey key;
    SocketChannel client;
    if (readSelector.selectNow()>0)
    keys=readSelector.selectedKeys();     
    it=keys.iterator();
    while(it.hasNext())
    key=(SelectionKey)it.next();
    if(key.isReadable())
    client=(SocketChannel)key.channel();
    buffer.clear();
    charBuffer.clear();
    client.read(buffer);
    buffer.flip();
    decoder.decode(buffer, charBuffer, false);
    charBuffer.flip();
    String em = charBuffer.toString();
    String aktion = em.substring(0,1);
    if(aktion=="-")
    //this don't come and em.substring(0,1) is -
    StringTokenizer st = new StringTokenizer(em,";");
    System.out.println("New Client:"+st.nextToken()+" on IP:"+st.nextToken());
    client.close();
    public static final void main(String args[]) throws Exception
    (new newserver()).start();
    sorry for my bad bad english ;)

    The code segment...
    if(aktion=="-")
    //this don't come and em.substring(0,1) is -
    StringTokenizer st = new StringTokenizer(em,";");
    System.out.println("New Client:"+st.nextToken()+" on IP:"+st.nextToken());
    will always return false. You are comparing the object reference of aktion to "-". The code should read:
    if(aktion.equals("-"))
    //this don't come and em.substring(0,1) is -
    StringTokenizer st = new StringTokenizer(em,";");
    System.out.println("New Client:"+st.nextToken()+" on IP:"+st.nextToken());
    The reason why it works when you hard code the values is because the Java comiler will only keep one object for each String literal. Thus:
    String aTest = "test";
    aTest=="test"; // This will return true but
    String aTest = getStringFromWhereElseThatIsTest();
    aTest=="test"; // Will most likely return false
    - Chris

  • NIO - Selector problem - when using more than one in same application

    Hi,
    I'm developing a multiplayer-server, which shall be able to handle at least 2000 concurrent clients. To avoid the use of 4000 threads for 2000 clients (a thread for each stream), I would like to use NIO.
    Problem:
    The server has of course a ServerSocketChannel registered with a Selector, and when clients connects, the SocketChannel's is received. IF these channels is registered (OP_READ) with the same Selector-instance as the ServerSocketChannel, there is no problem and the Selector recognizes when a registered SocketChannel is ready for OP_READ - BUT when the received SocketChannels is registered with another Selector-instance than the one the ServerSocketChannel is registered with, the Selector NEVER recognizes, when a SocketChannel is ready for OP_READ - why not and how do I solve the problem? Only one thread can service the same Selector-instance, and when both receiving many connections and read/write, this could easily be a bottleneck
    Following is the used code; 2 classes: ClientListener (has a ServerSocketChannel registered with a Selector) and ClientHandler (has another Selector where the SocketChannels is registered and a thread-pool that services all the SocketChannels, when they are ready for read/write):
    public class ClientListener {
      private static final int BACKLOG = 32;
      private int port;
      private Thread internalThread;
      private volatile boolean noStopRequested;
      private ServerSocketChannel ssc;
      private static Selector selector;
      private ClientHandler clientHandler;
      public ClientListener(ClientHandler clientHandler, String bindAddress, int port) throws InternalErrorException {
        this.clientClass = clientClass;
        this.clientHandler = clientHandler;
        this.noStopRequested = true;
        this.port = port;
        try {
          InetAddress inetAddress;
          if (bindAddress.equals(""))
            inetAddress = InetAddress.getLocalHost();
          else
            inetAddress = InetAddress.getByName(bindAddress);
          ssc = ServerSocketChannel.open();
          ssc.socket().bind(new InetSocketAddress(inetAddress, port), BACKLOG);
          ssc.configureBlocking(false);
          Runnable r = new Runnable() {
            public void run() {
              try {
                start();
              } catch (Exception e) {
                Log.echoError("ClientListener: Unexpected error: "+e.getMessage());
          internalThread = new Thread(r, "ClientHandler");
          internalThread.start();
        } catch (Exception e) {
          throw new InternalErrorException(e.getMessage());
      public static Selector selector() {
        return selector;
      private void start() {
        Log.echoSystem("ClientListener: Listening started at port "+port);
        try {
          selector = Selector.open();
          SelectionKey acceptKey = ssc.register(selector, SelectionKey.OP_ACCEPT);
          int keysAdded;
          while (noStopRequested) {
            SelectionKey key = null;
            keysAdded = selector.select(10000);
            if (keysAdded == 0)
              continue;
            Set readyKeys = selector.selectedKeys();
            Iterator i = readyKeys.iterator();
            while (i.hasNext()) {
              try {
                key = (SelectionKey)i.next();
                i.remove();
                if (key.isAcceptable()) {
                  ServerSocketChannel nextReady = (ServerSocketChannel)key.channel();
                  SocketChannel sc = nextReady.accept();
                  try {
                    clientHandler.registerClient(sc);
                  } catch (Exception e) { e.printStackTrace(); }
              } catch (CancelledKeyException cke) {
                System.out.println("ClientListener: CancelledKeyException");
        } catch (Exception e) {
          e.printStackTrace();
          try {
            ssc.close();
          } catch (IOException ioe) {/* Ignore */}
        Log.echoSystem("ClientListener: stopped");
      public void stop() {
    public class ClientHandler {
      private static final int INITIAL_WORKER_COUNT = 5;
      private int port;
      private Thread internalThread;
      private volatile boolean noStopRequested;
      private static Selector selector;
      private Manager manager;
      private WorkerPool pool;
      private ClientListener clientListener;
      public ClientHandler(Manager manager, String bindAddress, int port) throws InternalErrorException {
        this.manager = manager;
        this.noStopRequested = true;
        this.port = port;
        clientListener = new ClientListener(this, bindAddress, port);
        // initiating load-balanced worker-pool
        pool = new WorkerPool(INITIAL_WORKER_COUNT, (int)(manager.getMaxClients() * ClientWorker.CLIENT_FACTOR), 0.75f);
        for (int i=0; i < pool.getMinCount(); i++) {
          pool.addWorker(new ClientWorker(pool, manager));
        Runnable r = new Runnable() {
          public void run() {
            try {
              start();
            } catch (Exception e) {
              Log.echoError("ClientHandler: Unexpected error: "+e.getMessage());
        internalThread = new Thread(r, "ClientHandler");
        internalThread.start();
      public static Selector selector() {
        return selector;
      private void start() {
        Log.echoSystem("ClientHandler: Started");
        try {
          selector = Selector.open();
          int keysAdded;
          while (noStopRequested) {
            SelectionKey key = null;
            try {
              keysAdded = selector.select();
              Log.echoDebug("ClientHandler: out of select()");
              if (keysAdded == 0)
                continue;
              Set readyKeys = selector.selectedKeys();
              Iterator i = readyKeys.iterator();
              while (i.hasNext()) {
                try {
                  key = (SelectionKey)i.next();
                  i.remove();
                  if (key.isReadable()) {
                    key.interestOps(key.interestOps() & (~SelectionKey.OP_READ));
                    ClientWorker worker = (ClientWorker)pool.getWorker();
                    worker.process(key);
                  } else if (key.isWritable()) {
                    key.interestOps(key.interestOps() & (~SelectionKey.OP_WRITE));
                    ClientWorker worker = (ClientWorker)pool.getWorker();
                    worker.process(key);
                  } else {
                } catch (CancelledKeyException cke) {
                  Client client = (Client)key.attachment();
                  if (client != null) {
                    client.disconnect();
                    key.selector().wakeup();
            } catch (CancelledKeyException cke) {
              if (key != null) {
                Client client = (Client)key.attachment();
                if (client != null) {
                  client.disconnect();
                  key.selector().wakeup();
        } catch (Exception e) {
          e.printStackTrace();
        Log.echoSystem("ClientHandler: stopped");
      public void registerClient(SocketChannel sc) throws Exception {
        sc.configureBlocking(false);
        Client client = new Client(...);
        SelectionKey key = sc.register(selector, SelectionKey.OP_READ, client);
        key.selector().wakeup();
      public void stop() {
    }

    Ok, found the solution here: http://forum.java.sun.com/thread.jsp?forum=31&thread=282069
    "The select() method holds a lock on the selector that
    the register() method wants to acquire. The register()
    method cannot continue until the lock is relased and
    the select() method will not release it until some key
    is triggered. If this is the first key you're adding
    then select has nothing that will wake it up, ever.
    The result is, obviously, a deadlock.
    The solution is to have a queue of pending connections.
    You put your new connection in that queue. Then you
    wake up the selector and let that thread go through
    the queue, registering connections."

  • Nio write problem: server data sent isn't fully read by client

    Hi everyone,
    still writing away with my nio server and once again have run into
    some problems. Essentially my main problem is that when the server
    writes to the client, the write appears to output all the bytes in the
    write operation, but the client never accepts them all, even if a
    buffer has been manually allocated to the correct size of the data.
    As background my server will accept connections. When a connection
    is established I register OP_READ on the key. When a OP_READ trigger
    occurs the server accepts the clients request, processes it, then
    attaches the output to the SelectionKey as a ByteBuffer that has
    already been encoded. At this point I then register OP_WRITE on that
    SelectionKey (as a side note i'm running this server on XP and had
    read that registering OP_READ and OP_WRITE on the same selector was
    bad, but then it looked like there was a work around to this) and wait
    for an OP_WRITE trigger.
    When an OP_WRITE occurs on that key I run a new method (with heavy
    influences from the thread: http://forum.java.sun.com/thread.jsp?forum=11&thread=530825 and the taming the nio circus thread) which will grab the attachment and attempt to send it. The code has been written that IF the send cannot complete it should re-attach the remaining bytebuffer to the key and wait for another OP_WRITE to occur so it can send the remainder.
    The problem is that whenever I write (and for this test the amount im writing is approx 10100 bytes) the server appears to send it all (by checking the int returned from socketchannel.write()), but at the client end it never reads all the data that is sent.
    If i'm using a blocking socket client, then I get a java.net.SocketException: Connection Reset exception, whilst if i'm using a non-blocking client, I get no exception, just not the whole amount of data, even when i've statically allocated a receiving bytebuffer that is big enough.
    The following code is a class that is used to do the writing from the server:
       /* code for nio write model referenced from:
         * http://forum.java.sun.com/thread.jsp?forum=11&thread=530825
        class NIOWriteHandler {
            private ByteBuffer sendBuffer;
            private SelectionKey localSelectionKey;
            NIOWriteHandler(SelectionKey currentKey) {
                localSelectionKey = currentKey;
            public void doWrite() {
                localSelectionKey.interestOps(SelectionKey.OP_READ);  //deselect write,
                sendBuffer = (ByteBuffer)localSelectionKey.attachment();
                // perform the writing
                SocketChannel writingChannel = (SocketChannel)localSelectionKey.channel();
                if (writingChannel.isOpen()) {
                    int len = 0;
                    if (sendBuffer.hasRemaining()) {
                        try {
                            System.out.println("Sending chunks o data");
                            len = writingChannel.write(sendBuffer);
                            System.out.println("value of len: " + len);
                        } catch (IOException ioe) {
                            ioe.printStackTrace();
                            // call close method
                            System.out.println("CLOSE INVOKED at POINT 8");
                            closeComplete(localSelectionKey);
                    System.out.println("Second IF coming...");
                    if (sendBuffer.hasRemaining()) {
                        // if we get here then the previous write did not fully
                        // complete, so need to save data etc
                        System.out.println("Couldn't send all data this time...");
                        localSelectionKey.interestOps(SelectionKey.OP_WRITE|SelectionKey.OP_READ);
                        localSelectionKey.attach(sendBuffer);
                    } else {
                        sendBuffer = null;
                        closeComplete(localSelectionKey);
                // write complete at this stage
        }This is the basic block client that is incredibly dumb:
    import java.net.*;
    import java.util.*;
    import java.io.*;
    import java.nio.charset.*;
    import java.nio.channels.*;
    import java.nio.*;
    import java.nio.ByteBuffer;
    public class ServerTest {
        /* args 0 - the IP of the machine to connect to
           args 1 - the port number
           Simple client that connects to a specified IP & port, takes a line
           of input via stdin, sends that to the connected machine and prints
           out the response.
           Error handling and such isn't accounted for.
       public static void main (String args[]) throws Exception{
            Socket socket = new Socket(args[0], Integer.parseInt(args[1]));
            BufferedReader buffRead = new
                BufferedReader(new InputStreamReader((socket.getInputStream())));
            PrintStream ps =
                new PrintStream(socket.getOutputStream());
            Charset charset = Charset.forName("ISO-8859-1");
            BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("[CLIENT]Data to send: ");
            String data = stdin.readLine();
            ps.println(data);
            String returned = buffRead.readLine();
            while (returned != null) {
                System.out.println(returned);
                returned = buffRead.readLine();
            System.out.println("[CLIENT]End server response");
            buffRead.close();
            ps.close();
            socket.close();
    }And here is the non-blocking basic client (which dosn't actually close at the moment):
    import java.net.*;
    import java.util.*;
    import java.io.*;
    import java.nio.charset.*;
    import java.nio.channels.*;
    import java.nio.*;
    public class ServerTestNonBlock {
        /* args 0 - the IP of the machine to connect to
           args 1 - the port number
           Simple client that connects to a specified IP & port, takes a line
           of input via stdin, sends that to the connected machine and prints
           out the response.
           Error handling and such isn't accounted for.
       public static void main (String args[]) throws Exception{
            InetSocketAddress addr = new InetSocketAddress
                (args[0], Integer.parseInt(args[1]));
            SocketChannel sc = SocketChannel.open();
            sc.configureBlocking(false);
            Selector selector = Selector.open();
            System.out.println("Starting connection...");
            sc.connect(addr);
            while(!sc.finishConnect()) {
               System.out.println("1,2,3,4 I will keep on counting...");
            System.out.println("Connection established..");       
            Charset charset = Charset.forName("ISO-8859-1");
            CharsetEncoder encoder = charset.newEncoder();
            sc.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
            while (true) {
               int n = selector.select();
               if (n==0) {
                  continue;
               Set keys = selector.selectedKeys();
               Iterator it = keys.iterator();
               while (it.hasNext()) {
                  SelectionKey selKey = (SelectionKey)it.next();
                  if (selKey.isReadable()) {
                     // time to setup read
                     ByteBuffer incomingData =
                        ByteBuffer.allocateDirect(102000);
                     incomingData.clear();
                     int count;
                     while ((count = sc.read(incomingData)) > 0) {
                        System.out.println("Value of count: " + count);
                        // reading the data
                     System.out.println("Count value: " + count);       
                     int pos = incomingData.position();
                     incomingData.flip();
                     CharBuffer content = charset.decode(incomingData);
                     String inData = content.toString();
                     System.out.println(inData.trim());
                     System.out.println("[CLIENT]End server response");
                     System.out.println("Count value: " + count);       
                     System.out.println("Position value: " + pos);       
                     //sc.close();
                     //break;
                  if (selKey.isWritable()) {
                     BufferedReader stdin = new BufferedReader
                       (new InputStreamReader(System.in));
                     System.out.println("[CLIENT]Data to send: ");
                     String data = stdin.readLine();
                     ByteBuffer byteBufferOut = encoder.encode
                        (CharBuffer.wrap(data));
                     int length = sc.write(byteBufferOut);
                     System.out.println("Wrote: " + length + " bytes.");
                     selKey.interestOps(SelectionKey.OP_READ);
    }I'm kinda stuck at the moment and am making change for the sake of change without getting a good grasp of what is going on. If anyone can provide any help that'd be fantastic. If in the mean time I figgure something out i'll post a response.
    If you've gotten this far thanks a bunch for reading :)
    Cheers,
    Pete

    Hi Meesum,
    thanks for the reply :)
    I'm not convinced this is the error - as i've got two clients listed there, and the odd behaviour from both is that neither is getting through to the last of the data that is sent.
    If the null were the problem (which is only checked for in the basic dumb blocking client) i'd be expecting some sort of infinite loop or wait for more data from the server, not an abnormal termination (ala connection reset) from the server. I'll give it a shot anyhow, but I know that under a blocking write operation that that code worked fine.
    Thanks again though for the post, has got some of my cogs slowly turning :)
    Cheers,
    Pete

  • NIO: Strange problem when using ByteBuffer with non-blocking SocketChannel

    Hi,
    I have a server that uses multiplexed, non-blocking I/O with java.nio. When a client connects, the server waits for the message: <system cmd="knock"/>, returns a message and disconnects the client. The clients are shortly serviced in less than a second.
    But the server newer receive anything from about 20% of the clients - even though it is sent. Or with other words: it is received and the data is contained in the ByteBuffer - SocketChannel.read(ByteBuffer) - but a call to ByteBuffer.remaing() returns 0 !!
    ByteBuffer receiveBuf = ByteBuffer.allocate(65536);
    receiveBuf.clear(); // the code is elsewhere used for longer living clients
    int readBytes = channel.read(receiveBuf);
    receiveBuf.flip();
    StringBuffer sb = new StringBuffer();
    System.out.println(" * Remaining: "+receiveBuf.remaining()); // writes: ' * Remaining: 0'
    System.out.println(" * Received: "+new String(receiveBuf.array())); // writes: ' * Received: <system cmd="knock"/>'
    while(receiveBuf.remaining() >= 2) {
      byte b = receiveBuf.get();
      sb.append((char)b);
    System.out.println(" * sb content: "+sb.toString()); // writes: ' * sb content: 'The ByteBuffer clearly receives the correct data, but the ByteBuffer.remaining() returns 0 and therefore the StringBuffer will never have any content.
    The problem seems to occur randomly and for about 20% of the clients (simulated from the same computer and therefore has the same bandwidth and so on).
    Anyone knows what is going on, and how to solve the problem !?

    It's always possible in any read that the number of bytes read is less than the number of bytes requested. You need to keep reading until you have got everything you expected, and cope with every possible error condition on each iteration.
    EJP

  • Payload decoding problem

    Hi
    Im using 10.1.2.3 b2b with mlr#7. In edi 841 transaction im encoding a .jpeg(image) file in to base64 format and attaching it to the binary data section.The output raw edi data has the decoded jpeg file but it was corrupted.I donno how to get my original .jpeg(image) file.Same thing happens for .pdf format.Kindly help in resolving this issue.
    Regards
    venkat

    Hi Venkat,
    No there is no such rule and B2B will decode it in the same format.
    If you have applied MLR#7 successfully then it should work.
    Anyways, take the attachment content from the wiremessage and decod it using base 64 encoding manually and save it as a jpeg, and try to open. If then also you are not able to open then decode it twice and now save it as jpeg and try to open. I am asking this because prior to MLR#7 there was problem of attachments getting encoded twice.
    You may consider forwarding wire message and b2b log in debug mode to my id (in my profile).
    Regards,
    Anuj

  • Decode problem

    Hi,
    I have a problem with a decode function.
    I try to execute this select:
    select (DECODE(:CU_IES, 'D', (DECODE(:P_FISC, 1, a.flag1, 0, a.flag2) in (2,3,4)), (DECODE(:P_FISC, 1, a.flag1, 0, a.flag2) in (2,3,4,6))))
    from flag a
    and a get this error ORA-00907: missing right parenthesis.
    I try to this in Report Builder 6.0.8.11.3.
    I want to do this: when :cu_ies is 'D' to bring me flags 2,3,4 and if not 'D' to bring me flags 2,3,4,6. (All flags are from 0 to 6)
    What I have done wrong?
    Anyone can help me?

    Try using case instead of decode
    SELECT SUM(CASE :p_fisc,
                 WHEN 1 THEN
                  nvl(a.val_int, 0) + nvl(a.val_mod, 0) + nvl(a.val_dep_int, 0)
                 WHEN 0 THEN
                  nvl(a.val_int_int, 0) + nvl(a.val_mod_int, 0) +
                  nvl(a.val_dep_int, 0) + nvl(a.prov_dez_val, 0)
               END) val_inv1,
           0 val_inv2,
           a.cod_cat
      FROM flag a, MJ M
    WHERE a.identif_a = M.identif_a
       AND (CASE :P_FISC WHEN 1 THEN a.flag1 WHEN 0 THEN a.flag2
            END IN (2, 3, 4) OR :cu_ies = 'D')
    GROUP BY a.cod_cat
    UNION ALL
    SELECT 0 val_inventar1,
           SUM(CASE :p_fisc
                 WHEN 1 THEN
                  nvl(a.val_int, 0) + nvl(a.val_mod, 0) + nvl(a.val_dep_int, 0),
                 WHEN 0 THEN
                  nvl(a.val_int_int, 0) + nvl(a.val_mod_int, 0) +
                  nvl(a.val_dep_int, 0) + nvl(a.prov_dez_val, 0
               END)) val_inv2,
           a.cod_cat
      FROM flag a, MJ M
    WHERE a.identif_a = M.identif_a
       AND (CASE :P_FISC WHEN 1 THEN a.flag1 WHEN 0 THEN a.flag2
            END = 5 OR :cu_ies = 'D')
    GROUP BY a.cod_catHTH
    SS

  • Sorting: ORDER BY DECODE Problem on Pagination Query

    Hi,
    I've been searching around the easiest way to perform a dynamic "ORDER BY" clause and the "DECODE()" clause solution seem to be exactly what I am looking for. Unfortunately, It seems the DECODE function is not returning a correct column name value (I think it is returning NULL) since I'm receive the result set as if there was no ORDER BY clause.
    I need some help to get through this!
    Here the version with DECODE (not working)
    It is a Procedure with frstRow, nbRows and var_order as parameters
    The output returns the rows as if no ORDER BY was used
    SELECT c1, c2
    FROM
    SELECT ROWNUM rn, arv.*
    FROM A_AWA_AR arv
    WHERE ROWNUM < (frstRow + nbRows - 1) -- show only some rows determined by procedure
    ORDER BY DECODE(var_order, 1, c1, 2, c2, c1) -- sort by var_order
    WHERE rn BETWEEN frstRow AND (frstRow + nbRows)
    AND ROWNUM <= nbRows
    Here the version without DECODE (working)
    The output returns the rows as expected - ordered by c2 column
    SELECT c1, c2
    FROM
    SELECT ROWNUM rn, arv.*
    FROM A_AWA_AR arv
    WHERE ROWNUM < (frstRow + nbRows - 1) -- show only some rows determined by procedure
    ORDER BY c2 -- sort by var_order
    WHERE rn BETWEEN frstRow AND (frstRow + nbRows)
    AND ROWNUM <= nbRows
    -----

    Here are some results I've been getting... I will try the best I can to explain my problem.
    And by the way the table A_AWA_AR is a VIEW maybe this can help.
    My problem -- I think -- is that I don't understand how DECODE works. I should be a conditional IF-ELSE-THEN-like function but its behavior is not returning what I'm expecting.
    I need a solution where I will be able to sort the first lets say 10 rows using ROWNUM to tag row position (in sub-query) then the main query should only show the rows from 3rd postion to 7th position in the main query (as an example) with RN BETWEEN 3 AND 7. My solution does not work when I use decode but works when i pass the column name directly.
    Here is a simple query returning the values in the order they are found in the view:
    SELECT ROWNUM rn, ROW_ID, SR_NUM
    FROM A_AWA_AR
    WHERE ROWNUM < 10 Results:
    RN                                     ROW_ID          SR_NUM                                                         
    1                                      1-100876        1-60476802                                                     
    2                                      1-10087G        1-60476812                                                     
    3                                      1-10087Q        1-60476822                                                     
    4                                      1-10088A        1-60476842                                                     
    5                                      1-10088K        1-60476852                                                     
    6                                      1-10088U        1-60476862                                                     
    7                                      1-100894        1-60476872                                                     
    8                                      1-10089E        1-60476882                                                     
    9                                      1-10089O        1-60476892                                                      Now this is the query & result I would like to obtain (this is done pretty fast since it returns as soon as it reaches 9 sorted rows):
    SELECT ROWNUM rn, ROW_ID, SR_NUM
    FROM A_AWA_AR
    WHERE ROWNUM < 10
    ORDER BY SR_NUMResults:
    RN                                     ROW_ID          SR_NUM                                                         
    1                                      1-1RV9J7        1-107274499                                                    
    2                                      1-1RVXIF        1-107305575                                                    
    3                                      1-1SHY65        1-108332861                                                    
    4                                      1-22FOSR        1-125023563                                                    
    5                                      1-236F3X        1-126270717                                                    
    6                                      1-28P5EB        1-135542675                                                    
    7                                      1-29P2VY        1-137219038                                                    
    8                                      1-29ZNFH        1-137712221                                                    
    9                                      1-2BLWQR        1-140430339                                                     But with decode even a simple pseudo decode:
    SELECT ROWNUM rn, ROW_ID, SR_NUM
    FROM A_AWA_AR
    WHERE ROWNUM < 10
    ORDER BY DECODE(1,1,SR_NUM)Results:
    RN                                     ROW_ID          SR_NUM                                                         
    1                                      1-100876        1-60476802                                                     
    2                                      1-10087G        1-60476812                                                     
    3                                      1-10087Q        1-60476822                                                     
    4                                      1-10088A        1-60476842                                                     
    5                                      1-10088K        1-60476852                                                     
    6                                      1-10088U        1-60476862                                                     
    7                                      1-100894        1-60476872                                                     
    8                                      1-10089E        1-60476882                                                     
    9                                      1-10089O        1-60476892                                                      Here is the structure I'm trying to get and works when passing a column name:
    SELECT *
    FROM
        SELECT ROWNUM rn, ROW_ID, SR_NUM
        FROM A_AWA_AR
        WHERE ROWNUM < 10
        ORDER BY SR_NUM
    WHERE rn BETWEEN 3 AND 7Results:
    RN                                     ROW_ID          SR_NUM                                                         
    3                                      1-1SHY65        1-108332861                                                    
    4                                      1-22FOSR        1-125023563                                                    
    5                                      1-236F3X        1-126270717                                                    
    6                                      1-28P5EB        1-135542675                                                    
    7                                      1-29P2VY        1-137219038                                                     Now with decode (not working):
    SELECT *
    FROM
        SELECT ROWNUM rn, ROW_ID, SR_NUM
        FROM A_AWA_AR
        WHERE ROWNUM < 10
        ORDER BY DECODE(1,1,SR_NUM)
    WHERE rn BETWEEN 3 AND 7Results:
    RN                                     ROW_ID          SR_NUM                                                         
    3                                      1-10087Q        1-60476822                                                     
    4                                      1-10088A        1-60476842                                                     
    5                                      1-10088K        1-60476852                                                     
    6                                      1-10088U        1-60476862                                                     
    7                                      1-100894        1-60476872                                                      Thanks for the support!

  • Acrobat XI Decoder Problem

    An error says that Acrobat XI does not have a decoder for audio content.  The file is an MP3.  I have the latest Flash player installed.  Running Windows 8.  How do I fix?

    I would like to provide a sample, but I do not know how to do so from a proprietary disk that cost about $900.  Pat Willener's link seem to go to purchasing some cloud services.  I do not know of how I can provide you with a sample.  The problem is aggravating and did not occur with Windows 7 or the Reader version that I had before my prior computer bricked.  There has to be a way that you can work with me to fix this problem.  I would be happy to upload files if there was a clean and simple way to do so.  So far, I find this exercise to be a kluge and entirely unhelpful.  I took a screen shot of the error message and saved it in CS6 as a .psd.  You will not even let me upload that!  This is unhelpful.

  • How to feed CharsetDecoder (nio Buffer problems)

    Hi there,
    I have no idea how to feed bytes into a CharsetDecoder in presence of multibyte sequences. I am trying something along the following lines.
    If a multibyte char is being fed (I tried c3 +a4 = �), the first call to decode returns UNDERFLOW with bout.hasRemaining() == false as expected, but the 2nd call yields MALFORMED[1], no matter what rewind/flip method I throw in at // *1*
    I probably "misgrok" something here with Buffers. Can someone point out what?
      ByteBuffer bin = ByteBuffer.allocate(3);
      CharBuffer bout = CharBuffer.allocate(1);
      Charset cs = Charset.forName("UTF-8");
      CharsetDecoder dec = cs.newDecoder();
      public void addChar( int ch ) throws Exception {
        bin.put((byte)ch);
        bin.flip();
        CoderResult res = dec.decode(bin,bout,false);
        bout.flip();
        if( bout.hasRemaining() ) {
          emit( bout.get() );
          bin.clear();
          bout.clear();
        } else {
          bout.flip();
          //bin.flip(); // *1*
      }

    But the result character is already in the output buffer?! Applying my program code to ISO-8859-1, all character yield underflows and the data is successfully being converted.
    Here is a complete test program:
    import java.io.*;
    import java.nio.*;
    import java.nio.charset.*;
    public class DecoderTest {
      public static void main( String[] args ) throws Exception {
        dec = Charset.forName(args[1]).newDecoder();
        new DecoderTest().run(args[0]);
      ByteBuffer bin = ByteBuffer.allocate(3);
      CharBuffer bout = CharBuffer.allocate(1);
      static CharsetDecoder dec;
      public void run( String filename ) throws Exception {
        FileInputStream in = new FileInputStream(filename);
        int ch;
        while( (ch=in.read())>=0 ) {
          addChar(ch);
      public void addChar( int ch ) throws Exception {
        System.out.print( "byte "+(0xff & ch) + " => " );
        bin.put((byte)ch);
        bin.flip();
        CoderResult res = dec.decode(bin,bout,false);
        System.out.print( res + " => " );
        if( res.isError() ) {
          bin.clear();
          bout.clear();
        } else {
          bout.flip();
          if( bout.hasRemaining() ) {
            System.err.print( "char " + ((int)bout.get()) );
            bin.clear();
            bout.clear();
          } else {
            bout.flip();
           // what to do with bin here???
        System.err.println();
    }Passing in iso latin code lopoks like this:
    byte 98 => UNDERFLOW => char 98
    byte 228 => UNDERFLOW => char 228
    byte 104 => UNDERFLOW => char 104
    byte 32 => UNDERFLOW => char 32
    byte 98 => UNDERFLOW => char 98
    byte 228 => UNDERFLOW => char 228
    byte 104 => UNDERFLOW => char 104
    byte 10 => UNDERFLOW => char 10Utf-code looks like this:
    byte 98 => UNDERFLOW => char 98
    byte 195 => UNDERFLOW =>
    byte 164 => MALFORMED[1] =>
    byte 104 => UNDERFLOW => char 104
    byte 32 => UNDERFLOW => char 32
    byte 98 => UNDERFLOW => char 98
    byte 195 => UNDERFLOW =>
    byte 164 => MALFORMED[1] =>
    byte 104 => UNDERFLOW => char 104
    byte 10 => UNDERFLOW => char 10Message was edited by:
    HolgerK

  • Decoding-problems on subject

    Hello all,
    as far as I observed javamail does an automatic decoding of an eMail-subject for me. So a
    Subject: =?iso-8859-1?B?QW1hem9uLmRl?=
    automaticly becomes
    Subject: Amazon.de
    Now I get a message with the subject:
    Subject: openBC:=?UTF-8?Q?=20Ingo=20Gr=C3=BCneberg=20hat=20?= =?UTF-8?Q?Sie=20als=20Kontakt=20best?==?UTF-8?Q?=C3=A4tigt?=
    which will not be decoded by javamail. I tried to work around the problem and forced my application to decode the subject one more time - no result:
    System.out.println(MimeUtility.decodeText("openBC:=?UTF-8?Q?=20Ingo=20Gr=C3=BCneberg=20hat=20?= Sie als Kontakt best=?UTF-8?Q?=C3=A4tigt?="));
    -> openBC:=?UTF-8?Q?=20Ingo=20Gr=C3=BCneberg=20hat=20?= Sie als Kontakt best=?UTF-8?Q?=C3=A4tigt?=
    Then I thought the string would be the problem, but Thunderbird decodes the subject right!??
    Any sugestions? Thanks a lot in advance!
    Stephan
    Message was edited by:
    lotk

    First of all,i want to show you my code:
    package orlab.test;
    import java.io.File;
    import java.io.FileInputStream;
    import javax.mail.internet.MimeMessage;
    public class Program {
    * @param args
    * @throws Exception
    * @throws
    public static void main(String[] args) throws Exception {
    System.setProperty("mail.mime.decodetext.strict", "false");
    File dir = new File("c:/Mail");
    File[] files = dir.listFiles();
    for (int i = 0; i < files.length && i < 4; i++) {
    File f = files;
    if (!f.isFile()) {
    continue;
    FileInputStream fis = new FileInputStream(f);
    MimeMessage mm = new MimeMessage(null, fis);
    String rowHeader = mm.getHeader("Subject")[0];
    // System.out.println(MimeUtility.decodeText(mm.getSubject()));
    if (!rowHeader.equals(mm.getSubject())) {
    // continue;
    System.out.println("File\t\t:" + f.getName());
    System.out.println("Raw\t\t:" + rowHeader);
    System.out.println("Subject\t\t:" + mm.getSubject());
    fis.close();
    System.out.println("_______________");
    the raw mail data like this:
    _*Message-ID: <[email protected]>*_
    _*Date: Fri, 6 Jun 2008 19:06:47 +0900 (JST)*_
    _*Subject: SOME=?ISO-2022-JP?B?GyRCTU0wRjdvJUElJyVDJS8lNyE8JUgbKEI=?=*_
    this is the code which can decode "SOME=?ISO-2022-JP?B?GyRCTU0wRjdvJUElJyVDJS8lNyE8JUgbKEI=?=
    "to"SOME&#27096;&#26696;&#20214;&#12481;&#12455;&#12483;&#12463;&#12471;&#12540;&#12488;
    ", when i using gnu javamail.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Creative T7700 and DTS-100 Decoder (PROBLEMS, PLEASE HELP)

    Hi
    I purchased a Creative T7700 Speaker system and DTS-100 Decoder the other week but so far have had no luck getting it to work. I use a Gigabyte GA-K8NS ULTRA motherboard which came with an audio combo kit that supports 7.1. I did everything the logical way, Connecting the black wire to black socket in speaker and red tabbed wire to the red socket in speaker, I then connected each speaker to the sockets at the back of subwoofer. Then I connected the audio cables (grey, blue, orange, black) from sub to the Decoder switch, then connected the other wires from switch to the audio jacks at the back of the PC(blue plug to blue socket, black plug to black socket, orange plug to orange socket), The I connected the hardwired plugs in decoder switch to the decoder. Finally, I plugged the mains power to the decoder and subwoofer but got no sound at all. I checked the 7.1 was set up on computer and it was.
    HAS ANYONE ANY IDEAS WHY I GET NO SOUND? :smileyindifferent:
    1. I know I have power cause the circular green light on volume and bass controller is on.
    2. I have the decoder set to analogue and tried 1,2 and 3.
    3. I have tried changing the decoder switch between decoder and PC.
    4. I checked I have the decoder and subwoofer set to 7.1
    5. I know it isnt a problem with computer or decoder because when I plug earphones into the green audio jack in either the PC or Decoder I get sound (Although I have the decoder switch set to "PC"meaning the decoder just sits there with its little green lights making no difference at all).
    PLEASE HELP WITH THIS PROBLEM.
    Thanks

    I also am having this issue. Where I have installed the software for the M and after doing so I plug it in and get the Driver installation that fails to find drivers. If I try to open the creative explorer or the firmware upgrade released yesterday both say no device attached.

  • NIO first problems

    Hi guys,
    I experience very strange problem. Once a new connection is established and the key for the channel is registered for READ operations, the selector starts to continuosly provide me with the key having OP_READ set up:
    if (selector.select() == 0)
        continue;
    Iterator<SelectionKey> it = selector.selectedKeys().iterator();
    while (it.hasNext())
        SelectionKey key = (SelectionKey) it.next();
        // Accept new connection
        if (key.isAcceptable())
            ServerSocketChannel server = (ServerSocketChannel) key.channel();
            SocketChannel channel = server.accept();
            if (channel == null)
                continue;
            // Set the new channel nonblocking
            channel.configureBlocking(false);
            // Register it with the selector
            SelectionKey newKey = channel.register(selector, SelectionKey.OP_READ);
            // initialization of attachment ...
        if (key.isReadable())
            System.out.print("session index = "  +((ConnectionDescriptor)key.attachment()).session.sessionIndex);+
    +System.out.print(", counter "+  ++counter);+
    +System.out.println(", ops="+  key.readyOps());                   
            // read the data from channel
            if( counter == 10 ) {
                setEnabled(false);
                break;
        it.remove();
    }I use a python script in order to test the server:
    import socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect("localhost", 28000)
    s.send(b'\x00\x01')
    s.close()When I run the script I see the following output from the server:
    session index = 1, counter 1, ops=1
    session index = 1, counter 2, ops=1
    session index = 1, counter 3, ops=1
    header limit = 2
    body limit = 0
    process message 1
    session index = 1, counter 4, ops=1
    session index = 1, counter 5, ops=1
    session index = 1, counter 6, ops=1
    session index = 1, counter 7, ops=1
    session index = 1, counter 8, ops=1
    session index = 1, counter 9, ops=1
    session index = 1, counter 10, ops=1some parts of the code are omitted in order to keep it clear. If I do not stop it at 10th iteration it runs into endless loop.
    Why the key always says that the channel is "ready" to be read while I actually have already read the data?
    Thanks a lot in advance.
    Edited by: coderman on Jan 28, 2010 5:44 AM

    This is an example class you can reproduce the issue with:
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.net.ServerSocket;
    import java.nio.ByteBuffer;
    import java.nio.channels.ClosedChannelException;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.ServerSocketChannel;
    import java.nio.channels.SocketChannel;
    import java.util.Collection;
    import java.util.Iterator;
    public class MyServer
        private Selector selector;
        private int sessionSequence;
        public MyServer() throws IOException
            final ServerSocketChannel mainServerChannel = ServerSocketChannel.open();
            ServerSocket mainSocket = mainServerChannel.socket();
            mainSocket.bind(new InetSocketAddress(28000));
            mainServerChannel.configureBlocking(false);
            selector = Selector.open();
            mainServerChannel.register(selector, SelectionKey.OP_ACCEPT);
            int counter = 0;
            while (true)
                if (selector.select(1000) == 0)
                    continue;
                Iterator<SelectionKey> it = selector.selectedKeys().iterator();
                while (it.hasNext())
                    SelectionKey key = (SelectionKey) it.next();
                    if (key.isAcceptable())
                        ServerSocketChannel server = (ServerSocketChannel) key.channel();
                        SocketChannel channel = server.accept();
                        if (channel == null)
                            continue;
                        channel.configureBlocking(false);
                        SelectionKey newKey = channel.register(selector, SelectionKey.OP_READ );
                    if (key.isReadable())
                        System.out.print("counter " + counter);
                        System.out.print(", ops=" + key.readyOps());
                        ByteBuffer header = ByteBuffer.allocateDirect(10);
                        try
                            ((SocketChannel) key.channel()).read(header);
                        } catch (ClosedChannelException cce)
                            // the channel has been closed by the server
                        } catch (IOException ex)
                            // networking problem. Might be also connection lost.
                        header.flip();
                        System.out.println(", header limit = " + header.limit());
                        if (++counter == 15)
                            System.exit(0);
                    it.remove();
        public static void main(String[] argv)
            try
                new MyServer();
            } catch (IOException ex)
                ex.printStackTrace();
    }Here is the python script:
    import socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(("localhost", 28000))
    s.send(b'\x00\x01\x02')
    s.shutdown(1)This is what I get on my computer:
    counter 0, ops=1, header limit = 3
    counter 1, ops=1, header limit = 0
    counter 2, ops=1, header limit = 0
    counter 3, ops=1, header limit = 0
    counter 4, ops=1, header limit = 0
    counter 5, ops=1, header limit = 0
    counter 6, ops=1, header limit = 0
    counter 7, ops=1, header limit = 0
    counter 8, ops=1, header limit = 0
    counter 9, ops=1, header limit = 0
    counter 10, ops=1, header limit = 0
    counter 11, ops=1, header limit = 0
    counter 12, ops=1, header limit = 0
    counter 13, ops=1, header limit = 0
    counter 14, ops=1, header limit = 0

  • PLS help: animate gif decoding problem

    i am making a gif animation decoders
    using http://www.fmsware.com/stuff/gif.html
    after i decoded the gif, i could only view the animation by ACD See, but cant view by web browser(it only show the last frame of the gif) !!
    Thanks all you guy ~~~

    It seems this animated gif decoder doesn't function properly. Perhaps, you may use Jimi (http://java.sun.com/products/jimi/) to decode animated gif image :
    Enumeration images=Jimi.createJimiReader(inputStream, Jimi.SYNCHRONOUS).getImageEnumeration();

  • Decode Problem in Oracle 8.1.6

    In our test database(Oracle 8.1.6), the SQL statement below does not give an "invalid number" error.
    select contact_id from news_contact
    Where 1 = decode(contact_id ,'pressoffice', 1,'k')
    and contact_id = 'pressoffice'
    However, when I ran this same SQL statement on our production database(Oracle 8.1.6), I get an "invalid number" error on the 'k' on the decode.

    BTW, I think that [ code ], [ code ] and similar tags, should be properly documented in this forums, and their usage should be mandatory. This seems to be a week point of the administrators of the Oracle forums. Also a forum-level promotion of decent code formating styles will make a difference.
    Taking an example at random from another thread, imagine that instead of having to read and understand queries like this:
    select COUNT(1) AS X1,x1.close_dt,x1.open_dt FROM W_SRVREQ_D X1,
    ( SELECT w_day_d.day_dt AS snapshot_date FROM (SELECT to_date(nvl(max(date_wid),'20030531'),'yyyymmdd')+1 AS snapshot_date FROM bt_fault_snapshot_f) f , w_day_d , (SELECT CASE WHEN to_number(to_char(sysdate,'hh24')) <18 THEN trunc(sysdate - 1) ELSE trunc(sysdate)
    END AS lastdate FROM dual) currdate WHERE w_day_d.day_dt >= f.snapshot_date AND w_day_d.day_dt <= currdate.lastdate) day WHERE X1.STATUS='CLOSED' group by x1.close_dt,x1.open_dt
    we will see only queries like that:
    SELECT COUNT(1) AS X1,
           x1.close_dt,
           x1.open_dt
      FROM W_SRVREQ_D X1,
          (SELECT w_day_d.day_dt AS snapshot_date
             FROM (SELECT to_date(nvl(max(date_wid),
                          '20030531'),
                          'yyyymmdd')+1 AS snapshot_date
                     FROM bt_fault_snapshot_f) f,
                          w_day_d,
                  (SELECT CASE
                          WHEN to_number(to_char(sysdate,'hh24')) < 18  
                          THEN trunc(sysdate - 1)
                          ELSE trunc(sysdate)
                          END AS lastdate
                     FROM dual) currdate
            WHERE w_day_d.day_dt >= f.snapshot_date
              AND w_day_d.day_dt <= currdate.lastdate) day
    WHERE X1.STATUS = 'CLOSED'
    GROUP BY x1.close_dt,
              x1.open_dt

Maybe you are looking for