How to know Typing Status in XMPP openfire using Smack


I am developing chat application by using Openfire XMPP server. I can text chat between two user. But i want to know Typing status when some one is typing message. So i created a class :-

public class typingStatus implements ChatStateListener {

    @Override
    public void processMessage(Chat arg0, Message arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public void stateChanged(Chat arg0, ChatState arg1) {
        // TODO Auto-generated method stub
        System.out.println(arg0.getParticipant() + " is " + arg1.name());

    }

}

But i am confuse so that How will it work? I know that i need a packet where i can it in Listener. But i am unable to find that packet.

Please any one suggest, How will it work?

and also what is difference between Smack and asmack?

Thank you!




To enable ChatStateListener you need to create a custom MessageListener Class

public class MessageListenerImpl implements MessageListener,ChatStateListener  {

    @Override
    public void processMessage(Chat arg0, Message arg1) {
        System.out.println("Received message: " + arg1);

    }

    @Override
    public void stateChanged(Chat arg0, ChatState arg1) {
        if (ChatState.composing.equals(arg1)) {
            Log.d("Chat State",arg0.getParticipant() + " is typing..");
        } else if (ChatState.gone.equals(arg1)) {
            Log.d("Chat State",arg0.getParticipant() + " has left the conversation.");
        } else {
            Log.d("Chat State",arg0.getParticipant() + ": " + arg1.name());
        }

    }

}

Then you create MessageListener object

MessageListener messageListener = new MessageListenerImpl();

And then pass this in the create chat method

Chat newChat = chatmanager.createChat(jabber_id_of_friend, messageListener);

what is difference between Smack and asmack? <-- Check This




source - http://stackoverflow.com/questions/18436546/how-to-know-typing-status-in-xmpp-openfire-using-smack




Posted by linuxism
,

java - file memory

Development/Java 2014. 10. 30. 20:39


how to create new java.io.File in memory?


How can I create new File (from java.io) in memory , not in the hard disk?

I use java language. I don't want to save file in hard drive.



To write to a stream, in memory, use:

new ByteArrayOutputStream();


Maybe you are confusing File and Stream:

  • File is an abstract representation of file and directory pathnames. Using a File object, you can access the file metadata in a file system, and perform some operations on files on this filesystem, like delete or create the file. But the File class does not provide methods to read and write the file contents.
  • To read and write from a file, you are using a Stream object, like FileInputStream or FileOutputStream. These streams can be created from a File object and then be used to read from and write to the file.

You can create a stream based on a byte buffer which resides in memory, by using a ByteArrayInputStream and a ByteArrayOutputStream to read from and write to a byte buffer in a similar way you read and write from a file. The byte array contains the "File's" content. You do not need a File object then.

Both the File... and the ByteArray... streams inherit from java.io.OutputStream and java.io.InputStream, respectively, so that you can use the common superclass to hide whether you are reading from a file or from a byte array.



source - http://stackoverflow.com/questions/17595091/how-to-create-new-java-io-file-in-memory




'Development > Java' 카테고리의 다른 글

java - json-simple parse  (0) 2014.08.19
java - URLConnection, cookie, session  (0) 2014.04.17
java - local host ip address  (0) 2014.02.13
java - HttpURLConnection  (0) 2014.02.07
java - 화폐 원 단위 콤마 표시  (2) 2013.10.02
Posted by linuxism
,


I am using Spring MVC for my web application. My beans are written in "spring-servlet.xml" file

Now I have a class MyClass and i want to access this class using spring bean

In the spring-servlet.xml i have written following

<bean id="myClass" class="com.lynas.MyClass" />

Now i need to access this using ApplicationContext

ApplicationContext context = ??

So that I can do

MyClass myClass = (MyClass) context.getBean("myClass");

How to do this??



@Autowired
private ApplicationContext appContext;



source - http://stackoverflow.com/questions/21827548/spring-get-current-applicationcontext





'Framework & Platform > Spring' 카테고리의 다른 글

spring - ServletContext  (0) 2015.07.16
spring - headers="Accept=*/*"  (0) 2014.12.26
spring - restTemplate example  (0) 2014.09.12
spring - @Autowired @Resource @Qualifier  (0) 2014.09.05
spring data - jpa insert  (0) 2014.08.24
Posted by linuxism
,