Solved

Java - Printing buffer data together

Posted on 2016-07-15
4
40 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
  • 2
  • 2
4 Comments
 
LVL 26

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 26

Accepted Solution

by:
dpearson earned 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now