Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Java - Printing buffer data together

Posted on 2016-07-15
4
Medium Priority
?
56 Views
Last Modified: 2016-07-17
Hello there,

I have this piece of code and want to print out the data in the buffer,cam somebody please guide me how can i achieve it.

cheers
Zolf

 Buffer buf = Buffer.buffer();
            buf.appendByte((byte) 0x02).appendString("CLR").appendByte((byte) 0x03)
                    .appendByte((byte) 0x1b).appendString("K1").appendByte((byte) 0x0d)
                    .appendByte((byte) 0x1b).appendString("C").appendByte((byte) 0x0d)
                    .appendByte((byte) 0x1b).appendString("K2").appendByte((byte) 0x0d)
                    .appendByte((byte) 0x1b).appendString("C").appendByte((byte) 0x0d)
                    .appendByte((byte) 0x1b).appendString("K3").appendByte((byte) 0x0d)
                    .appendByte((byte) 0x1b).appendString("C").appendByte((byte) 0x0d)
                    .appendByte((byte) 0x1b).appendString("K4").appendByte((byte) 0x0d)
                    .appendByte((byte) 0x1b).appendString("C").appendByte((byte) 0x0d);
                    socket.write(buf);

Open in new window

0
Comment
Question by:zolf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:dpearson
ID: 41714725
I don't think Buffer here is the standard Java buffer class - i.e. java.nio.Buffer

I suspect this is an internal class - in which case you'd need to look inside that class to see how it is representing the data and how to print it out.

If it contains a ByteBuffer then that has a getChar() method which you can use to read and print the current contents of the buffer.

Doug
0
 

Author Comment

by:zolf
ID: 41715035
thanks for your comments.

Yes I am using a 3rd party buffer class and the link to it is http://vertx.io/docs/apidocs/io/vertx/core/buffer/Buffer.html
0
 
LVL 28

Accepted Solution

by:
dpearson earned 2000 total points
ID: 41715037
Given that I would suggest working with one of these methods:

String      getString(int start, int end)
Returns a copy of a sub-sequence the Buffer as a String starting at position start and ending at position end - 1 interpreted as a String in UTF-8 encoding

Or if that doesn't work try this one:

byte[]      getBytes(int start, int end)
Returns a copy of a sub-sequence the Buffer as a byte[] starting at position start and ending at position end - 1

In both cases, end would be:
int      length()
Returns the length of the buffer, measured in bytes.

That should give you access to the data in the buffer.

If length returns 0, then you should try call this before the socket.write(buf) which may empty the buffer, depending how it is written.

Hope that helps,

Doug
0
 

Author Closing Comment

by:zolf
ID: 41715065
cheers
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question