Nio Question - get() method in ByteBuffer

I m working on the telnet client program, in the negotiation phase of telnet
connection, my telnet server returns me FF FB 03 FF FB 01 (WILL SUPPRESS-GO-AHEAD
WILL ECHO), I read those bytes into a ByteBuffer, and trying to print them out
to the screen.
static ByteBuffer bb = ByteBuffer.allocateDirect(1024);
public static void main(String args[]) throws IOException{
InetSocketAddress isa = new InetSocketAddress("192.168.1.1", 23);
SocketChannel sc = null;
try {
sc = SocketChannel.open();
sc.connect(isa);
bb.clear();
sc.read(bb);
bb.flip();
System.out.println(bb.get());
For byte FF FB 03 FF FB 01, I got result like -1 -5 3 -1 -5 1
it seems to me that "print" can't print byte to screen, I therefore tried
this "new Byte(bb.get()).intValue()", however it gives me the same result
03 01 are properly displayed, does it mean java interprets 1111 1111 as negative?
how do I display them as integer value?

Integer.toHexString(int) will return a string containing the hexadecimal representation of the value of the int.

Similar Messages

  • HttpURLConnection and HEAD/GET methods

    I am attempting to validate whether an HTML page exists or not.
    I have found that, for about 7% of the pages checked, HEAD and GET methods return different response codes.
    I have structured my code such:
    1) make initial check using HEAD method
    2) for non valid (200) response codes, recheck the page using the GET method.
    In this case about 75% of the pages that failed using the HEAD method will work when using the GET method.
    So, I guess my questions are:
    1) Does anybody know why HEAD/GET return different response codes?
    2) Does anybody know a better way to check if a page exists?
    Here is the sample program I am using with a few URLs that exhibit this behaviour:
    import java.io.IOException;
    import java.net.HttpURLConnection;
    import java.net.InetAddress;
    import java.net.URL;
    import java.net.UnknownHostException;
    public class Internet
         private final static String DEFAULT_LOCAL_HOST = "127.0.0.1";
         private URL url;
         private HttpURLConnection http;
         private int responseCode;
         private String responseMessage;
         public Internet(URL url)
              this.url = url;
         public boolean isValid()
              try
                   //  Make first attempt using a HEAD request
                   http = (HttpURLConnection)url.openConnection();
                   http.setRequestMethod( "HEAD" );
                   http.connect();
                   System.out.println( "head: " + http.getResponseCode()
                   + " : " + http.getResponseMessage() );
                   //  GET seems to do a better job, try again
                   if ( http.getResponseCode() != HttpURLConnection.HTTP_OK)
                        http = (HttpURLConnection)url.openConnection();
                        http.setRequestMethod( "GET" );
                        http.connect();
                        System.out.println( "get:  " + http.getResponseCode() );
                   responseCode = http.getResponseCode();
                   responseMessage = http.getResponseMessage();
                   if (http.getResponseCode() == HttpURLConnection.HTTP_OK)
                        return true;
                   else
                        System.out.println( http.getResponseMessage() );
                        return false;
              catch (IOException e)
                   responseCode = -1;
                   responseMessage = e.getMessage();
                   System.out.println( e );
                   return false;
         public static void main(String[] args)
              throws Exception
              URL url = new URL( "http://www.trca.on.ca" );
              Internet internet = new Internet( url );
              System.out.println( internet.isValid() );
              url = new URL( "http://school.discovery.com/sciencefaircentral" );
              internet = new Internet( url );
              System.out.println( internet.isValid() );
              url = new URL( "http://www.amazon.com" );
              internet = new Internet( url );
              System.out.println( internet.isValid() );
    }

    Using my sample program:
    1) about 3K of data is transferred
    2) it runs in about 8 seconds
    Using InputStream in = http.getInputStream():
    1) about 73K of data is transferred
    2) it runs in about 15 seconds
    Using the getInputStream() method causes the entire file to be transmitted (even though I don't use any read() methods). I don't care about the data.
    I want the check to be as fast as possible which is why I use the HEAD method. It doesn't transfer the contents of the file. But why in some cases does it show a response code other than 200?

  • Can I change the email where the security questions get send to if I forgot ??

    Can I change the email where my security question gets send to it says " send reset security info email to [d******@hotmail]
    and I don't know who's email is that ? can I change that and if I can can you guys help me please it means a lot

    Not without correctly answering two of them. You need to ask Apple to reset your security questions; ways of contacting them include phoning AppleCare and asking for the Account Security team, clicking here and picking a method for your country, and filling out and submitting this form.
    They wouldn't be security questions if they could be bypassed without Apple verifying your identity.
    (104009)

  • Help with efficiency for insert/get methods?

    I am not an expert when it comes to run times and I am wondering what the most efficient data structures would be for a program I am making. I need to:
    Go through a large document in which each line is formatted as: (String Integer), and add the string & integer to some sort of data structure. The list of string/integers is large and I need to be able to access the information in the data structure efficiently. Right now I am using a scanner to read the doc and a TreeMap<String, Integer> to store the info. The get method for the TreeMap is fine, but processing the document is a little slow.
    What do you think? TreeMap, hashing, balanced search tree? Remember, the insert and get methods are the two that need to be most efficient.

    Why are you using a TreeMap? Is the order of iteration important to you?
    If not, then you can probably get better performance using a HashMap, properly configured. The TreeMap has O(n) performance for get/put. while HashMap has constant-time performance. If you properly configure the initialCapacity and loadFactor for the HashMap you can get very efficient puts by reducing the number of re-hashes that are needed during map-growth. Note that if you retrieve the data from the Map using an iterator (rather than just calling get()) then you have to be more careful with these settings because they affect the total number of buckets - which can affect the speed of iteration.
    You should also run your code through a profiler. Are you sure that the put() operation is the slow step when reading from the file? It may be that your file access is really the slow step, and so modifying the data structure would have little or no effect. You might consider different methods for accessing the file data, perhaps something from thew NIO package would help speed things up (I am not particularly sure though - I am not very familiar with NIO).

  • GET Method with long query string

    Hi there,
    Not sure if this has already been answered. Sorry if it has!
    I have a Biztalk application which does a pass-through for all http requests. It is using WCF-WebHttp transport type with URL mapping of /*.
    It works fine except for GET method that has query string longer than 256 characters. It chokes with following exception:
    The adapter "WCF-WebHttp" raised an error message. Details "System.ArgumentOutOfRangeException: The value of promoted property cannot exceed 256 characters. Property "To" Namespace "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties".
    My question is is there a workaround for this e.g. extend the string length limit? 

    Hi Karsten,
    Try giving the one part of URL in address box and other pass the arguments inside HTTP Method and URL Mapping dialog.
    Eg:
    Address (URI) : https://btstecheddemostorage.blob.core.windows.net
    <BtsHttpUrlMapping>
    <Operation Name="ListFiles"
    Method="GET" Url="/{mycontainer}?restype=container&amp;comp=list"
    /> </BtsHttpUrlMapping>
    Thank YOu,
    Tamil

  • Abstract class with set and get methods

    hi
    how to write set and get methods(plain methods) in an abstartc class
    ex: setUsername(String)
    String getUsername()
    and one class is extending this abstract class and same methods existing in that sub class also..... how to write......plz provide some ideas
    am new to programming....
    asap
    thnx in advance

    yes... as i told u.... i am new to coding......
    and my problem is ..... i have 2 classes one is abstract class without abstract methods.. and another class is extending abstract class.....
    in abstract class i have 2 methods...one is setusername(string) and getusername() ..... how to write these two methods.... in abstract class i have private variables username...... when user logins ..... i need to catch the user name and i need to validate with my oracle database and i need to identify the role of that user and based on role of that user i need to direct him to appropriate jsp page.......
    for that now i am writing business process classes..... the above mentioned two classes are from business process.....
    could u help me now
    thnx in advance

  • Oracle.jbo.AttrValException: JBO-27019: Get method for attribute

    Hi Guys,
    I am trying to add a new column to Oracle quoting.It has already been customized by some consultant few years back. I followed the note 392728.1 on metalink and also have the documentation by the previous consultant but getting the error oracle.jbo.AttrValException: JBO-27019: Get method for attribute Draft in HeaderVO could not be resolved after adding my column, when I try to print the quote.
    Here are the steps I took
    1) added a column to the query (at the end) in HeaderVO.xml
    2) added the below code in the HeaderVO.xml
    <ViewAttribute
    Name="DRAFT"
    IsQueriable="false"
    IsPersistent="false"
    Precision="100"
    Type="java.lang.String"
    AliasName="DRAFT"
    ColumnType="VARCHAR2"
    Expression="DRAFT"
    SQLType="VARCHAR" >
    <DesignTime>
    <Attr Name="_DisplaySize" Value="100" />
    </DesignTime>
    </ViewAttribute>
    3). Modify HeaderVORowImpl.java file to add setters and getters for the newly added view attribute. For example,
    a) case 67: //
    setDRAFT((String)obj);
    return;
    b) case 67:
    return getDRAFT();
    c) ublic void setDRAFT(String s)
    setAttributeInternal(67, s);
    public String getDRAFT()
    return (String)getAttributeInternal(67);
    d) protected static final int DRAFT = 67;
    Everything is dont exactly as per the manual but not sure why I am getting this issue. Any help will be appreciated.

    a) case 67: //
    setDraft((String)obj);
    return;
    b) case 67:
    return getDraft();
    c)public void setDraft(String s){
    setAttributeInternal(67, s);
    public String getDraft(){
    return (String)getAttributeInternal(67);
    d) protected static final int DRAFT = 67;
    can u change it as explained above.. setDRAFT should be setDraft.. and getDRAFT should be getDraft..
    and make sure that the index.. number is exactly matching with the attribute order in the VO

  • Can't get my class's getter method to work properly.

    Hello, I am new to Java programming, although I come from C and C++. This is my first post. I am working on a basic Library application that can Checkout and Return books. Eventually I would like to add the ability to read from and write to an XML file containing data for every book.
    My problem right now is that I cannot get my getter method within my Book class to work properly. When I call getData() from within main, and pass the appropriate arguments, instead of filling the variables with that object's data, it leaves them blank! Please help me.
    Here is my method within the Book class, the person and id_num are private.
    /* Gets general Book Instance Data and fills parameters with it */
         public void getData(String n, int num, String c, String d)
              n = this.person;
              num = this.id_num;
              c = this.checkout_date_string;
              d = this.due_date_string;
         }Here is how I am attempting to use it in main:
    String name = "";
    int number = 0;
    String checkout = "";
    String due = "";
    Book book1;
    /*Sets person = John Smith and id_num = 10763*/
    book1 = new Book("John Smith", 10763);
    /*Gets Checkout (todays) date and sets a due date in 2 weeks*/
    book1.Checkout();
    book1.getData(name, number, checkout, due);
    System.out.println("Book1:\n Checkout Date: " + checkout +
                             "\n Due Date: " + due + "\n Is it late: " + book1.isLate() +
                             "\n Person who checked it out: " + name + "\n ID number: " + number +
                             "\n ");Then, Here is the Output:
    Book1:
    Checkout Date:
    Due Date:
    Is it late: false
    Person who checked it out:
    ID number: 0
    Edited by: 987158 on Feb 9, 2013 11:52 AM

    >
    Well I went ahead and made separate methods to return each value. I suppose that will work just as well, especially since now I don't have to declare a bunch of strings and int's to hold the data and pass to the method.
    >
    Well this would never work anyway
    public void getData(String n, int num, String c, String d)None of those can be changed within the method. Strings are immutable and 'int' is passed by value. Each of those parameters will have the same value after the method exits as they did before it was called.
    Your book class should be using 'setters' to set the value of its instance variables.

  • How can I implement a get method that lets me divide two values, Help plz

    I need to implement a method that divides the values return by two other methods but I keep getting an error message, I think its divide by zero error ( I am not too sure on the exact error msg as I do not have java installed on this pc as yet), here is my example,
    I have two get methods that take an int value so say
    getValueOne() as method one
    getValueTwo() as method two
    Now I have a third method that does the following,
    Public int getValueThree() {
    int value =0;
    value = (getValueOne() / getValueTwo())
    return value;
    I am not two sure on the exact code but it does something like this and I get an error. Could someone please guide me how I can successfully implement a get method that divides two values that are returned by two methods.
    Thanks,
    Zub

    Hi, thanks for your reply. Right, how can I go about to throw an exception? I can definitely give the exact code and error message tomorrow when I can access my home pc.
    And you are right there are some values that are zero! I am not very sure what throwing an exception means to be honest. Could you please give an example?
    Thanks...

  • No Getter Method Error

    I had a working JSP/Struts application. I added a new data page and struts forward, and started getting:
    No getter method for property Fullname6 of bean org.apache.struts.taglib.html.BEAN
    errors.
    I have confirmed that the Fullname6 is referenced in the UIModel.xml file. My changes were only to add a read-only table to the jsp that is failing, so I don't see how that could be causing this error. I made no changes to the struts action that forwards to this page.
    What is going on here? Anybody have any ideas?

    I know about the link that you've sent.
    We don't have a specific form bean for this, as we have 'DataForm' which takes care of get/setter method for the attributes. I am using ADF, JSP, Struts and parameterized where clause in my VO. I do not know how to procede as it doesn't allow me to create the form bean.
    Thanks,

  • No getter method for property user of bean Problem

    Hi everyone,
    I am new to this struts. I have a samll application to check login. When I run my application I get this message in my server console
    No getter method for property user of bean org.apache.struts.taglib.html.BEAN
    I saw the previous forum for the same topic. I have checked my property names start with appropriate cases. Here is my code
    %@ page language="java" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <html>
    <head><title>Login</title></head>
    <body>
    <html:form action="submit.do">
    <table width="100%" border="0" height=75%>
    <tr>
    <td align="right" >UserName: </td>
    <td><html:text property="user"/></td>
    <tr>
    <tr>
    <td align="right" >Password: </td>
    <td><html:text property="password"/></td>
    </tr>
    <tr>
    <td colspan=2 align="center"><html:submit/></td>
    </tr>
    <tr>
    <td colspan=2 align="center"><html:errors/></td>
    </tr>
    </table>
    </html:form>
    </body>
    </html>
    import javax.servlet.http.HttpServletRequest;
    import org.apache.struts.action.*;
    import java.util.*;
    * @author skannan
    * To change this generated comment edit the template variable "typecomment":
    * Window>Preferences>Java>Templates.
    * To enable and disable the creation of type comments go to
    * Window>Preferences>Java>Code Generation.
    public class LoginForm extends ActionForm
    private String user = null;
    private String password = null;
    /* user */
    public String getUser()
    return (this.user);
    public void setUser(String user)
    this.user = user;
    /* password */
    public String getPassword()
    return (this.password);
    public void setPassword(String password)
    this.password = password;
    public ActionErrors validate(ActionMapping mapping,
    HttpServletRequest request) {
    // Log the forms data
    servlet.log("Lastname:" + user);
    servlet.log("Address:" + password);
    // Check for mandatory data
    ActionErrors errors = new ActionErrors();
    if (user == null || user.equals("")) {
    errors.add("User", new ActionError("error.user"));
    if (password == null || password.equals("")) {
    errors.add("Password", new ActionError("error.password"));
    return errors;
    I am missing anything in my config files. Please I need help.
    Thanks!

    I did check my struts-config file
    Here is the part of my file
    <!-- ========== Form Bean Definitions ================= -->
    <form-beans>
    <form-bean name="loginForm"
    type="kannan.struts.trailer.checkin.LoginForm"/>
    <form-bean name="checkInForm"
    type="kannan.struts.trailer.checkin.CheckInForm"/>
    </form-beans>
    <!-- ========== Action Mapping Definitions ============ -->
    <action-mappings>
    <action path="/submit"
    type="kannan.struts.trailer.checkin.LoginAction"
    name="loginForm"
    input="/login.jsp"
    scope="request">
    <forward name="success" path="/checkIn.jsp"/>
    <forward name="failure" path="/login.jsp"/>
    </action>
    Still I am getting the error

  • Null pointer exception in getter method

    I am trying to have a getter method that returns a collection. The method is supposed to get a list of files from a directory and returns the collection. I am instantiating the List in the method and the converting an array into the List using asList. Then I am trying to return the list to the main method.
    When I put this code in the main method I get the result I want, but when I try to put it in the getter method and call it from main I get a NullPointerException compile error.
    I need help understanding what I am doing wrong when I move this code out of the main method and into another non static method.

    I was looking around at other posts and noticed they
    give more code than I was. I was trying to save you
    some reading but now I see I just made it harder.No problem. It can be difficult to know just how much code to post to get all the relevant stuff but not a bunch of extraneous junk.
    The problem is you have two different currentDirectory variables. The member variable (declared just inside public class FileBrowser and a method (or "local") variable declared in main. The local one in main hides or shadows (those two terms are similar in Java, and I forget the details of which is which) the member variable.
    When you set the one in main, it doesn't affect the member variable. The local one in main only exists inside of main.
    To fix this, change this line inside of main: File currentDirectory = new File(System.getProperty("user.dir")); to this: currentDirectory = new File(System.getProperty("user.dir")); By having the class name File there you're declaring a new variable. Without the class name, you're just using the existing member variable.

  • **URGENT** No getter method for property searchText of bean org.apache.stru

    I'm implementing a query page as described in the HowTo ADF_ComplexMasterDetail.zip
    When running the query page, I'm receiving the error:
    javax.servlet.jsp.JspException: No getter method for property searchText of bean org.apache.struts.taglib.html.BEAN
    I have my searchEmployees writen and 'exposed' (at least I can see it in the Data palette). But seems like something is missing, and can't find this searchText beam property specified in the html:text tag.
    Can someone help in this one?
    Here is the Help description inside the HowTo example:
    Section 3
    queryEmployees
    queryEmployeesInDept provides an interface for entering a simple search criteria for querying a list of
    employees. This does not use the Find mode Query By Example functionality that the other query screens
    use, but rather presents a much simpler search interface. The actual search is carried out using a
    function
    searchEmployees that the underlying view object exposes. (See the EmployeesView view object in the
    model project)
    1. Drop a new Data Page onto the page flow diagram call it queryEmployees
    2. In the page flow diagram, drag the searchEmployees operation from the AllEmployeesView
    collection in the Data Control Palette and drop it on top of the new Data Page. This will cause the
    framework to run a search whenever the page is called.
    3. In the Structure pane, locate the queryEmployees node and expand it, select the child node
    paramNames[0], and change it's value attribute to ${param.searchText}. This will pass the URL
    parameter searchText on to the business method to qualify the query.
    4. Drill down into the page and expand the Data Control Palette to select the AllEmployeesView
    collection. Set the Drag and Drop as: list to Read-OnlyTable. Then drag the collection onto the page.
    This will create a tabular containing the query results.
    5. Select the Struts HTML component palette and drag a Form onto the page above the output table. Set
    the handling action to this Data Page (queryEmployees.do)
    6. Drag a text field from the component palette inside of this new form. Set the property attribute of
    the
    <html:text> tag to searchText (the same value you used in the paramNames[0] for the Data Page)
    7. Create a new submit button in the form to submit the search. Set the property attribute of the button
    to
    event_search.
    8. Finally we need to subclass the data page to prevent the search action from being fired when it is not
    appropriate for the page ( for instance when we first display it). To do this we need to Go to Code on
    the Data Page's context menu, and override the invokeCustomMethod() method:
    * We only want to invoke the custom method i.e. the call to change
    * the Where clause on the collection, if the Action has been called with
    * a search event on the page with a search term supplied.
    * If the user got here via a link or another event, we bypass the model call
    * unless a URL parameter event=search is supplied, in which
    * case the method will also be called.
    protected void invokeCustomMethod(DataActionContext actionContext)
    List events = actionContext.getEvents();
    // If the event is "search" do the custom event call
    if ((events != null) && (events.contains("search")))
    String searchTerm = (String)((DynaActionForm)actionContext.getActionForm())
    Get("searchText");
    if (searchTerm != null)
    super.invokeCustomMethod(actionContext);
    }

    Solved with Oracle JDeveloper HowTo:
    Creating Search Pages with Both Fixed and Dynamic Criteria
    Author: Steve Muench, Oracle ADF Development Team
    Date: September 16, 2004
    http://www.oracle.com/technology/products/jdev/howtos/10g/dynamiccrit/index.html

  • Authentication syntax for HTTP GET method using TCP functions in Labview on linux

    Hi,
    Currently, I am trying to communicate to web server. I have Labview installed on a Linux machine. The HTTP function blocks and other labview functions do not work. Hence, I am building a HTTP code string using TCP functions (port 80) to talk to the web server. I am successfully able to fetch a response from web sites (example www.ni.com) from my vi. However, when I try to communicate to my web server, it does not work. It requires an authentication. I am able to open http://ipaddress in my browser from my machine using username and password. Can someone help with Authentication string requirement for GET method?
    so far the string is:
    GET /index/ HTTP/1.1
    Host: http://xx.xx.xx.xx

    An easy option would be to try http://userassword@server syntax for the URL.
    Else I posted a Twitter fetcher once (won't work anymore since Twitter moved to Oauth authentication) at LAVA. Based on code from @cloew.
    The code is part of this LLB.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • Problem extending standard ViewReceiptsSearchVO view object with logic on get method

    Hi All,
    EBS 12.1.3
    Database 11.2.0.3
    I am trying to extend the 3 VOs related to ViewReceiptsSearch.  I extended a seeded ViewReceiptsSearchVO view object.  I haven't made any changes yet, no columns added, nothing altered.  When I run this substitution, the "Received" column is null.  This column in the view used for the view object only selects NULL and uses the getter method for the attribute to populate the value.  The generated extension getter calls getAttributeInternal and skips the logic in the standard getter and the substituted view object is displaying the null in the screen.  The below discussion explains the problem very well except that the original posted had the issue in 11.5.10.2.  I am having this issue with 12.1.3.
    Problem extending standard view object with logic on get method
    The 3 VOs that I am having the problem are:
    ViewReceiptsSearchVO
    ViewReceiptsSearchReqVO
    ViewReceiptsSearchSupplierVO
    What do I need to do to get the "Received" column populated?  Please let me know any additional information you want to troubleshoot the issue.
    Thanks.

    Hi,
    Can you Please Share Extended ViewReceiptsSearchVO.xml and .jpx File?
    Thanks,
    Dilip

Maybe you are looking for