Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdwp/ReplyPacket.java
41161 views
/*1* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.share.jdwp;2425import nsk.share.*;26import java.util.Vector;2728/**29* This class represents a JDWP reply packet.30*/31public class ReplyPacket extends Packet {3233/** Error code constant. */34// public final static int errOk = JDWP.Error.NONE;35/** Error code constant. */36// public final static int errWrongPacketSize = 0x400;37/** Error code constant. */38// public final static int errNotAvailable = 0x401;39/** Error code constant. */40// public final static int errEvent = 0x4064;4142/**43* Make empty reply packet.44*/45public ReplyPacket() {46super();47}4849/**50* Make reply packet with data from the specified byte buffer.51*/52// public ReplyPacket(ByteBuffer packet) {53public ReplyPacket(Packet packet) {54super(packet);55}5657/**58* Return value of the "error code" field of JDWP reply packet.59*/60public int getErrorCode() {6162int err = 0;63try {64err = (int) getID(ErrorCodeOffset, 2);65}66catch (BoundException e) {67throw new Failure("Caught unexpected exception while getting error code from header:\n\t"68+ e);69}7071return err;72}7374/**75* Set value of the "error code" field of JDWP reply packet.76*/77public void setErrorCode(long err) {78try {79putID(ErrorCodeOffset, err, 2);80}81catch (BoundException e) {82throw new Failure("Caught unexpected exception while setting error code into header:\n\t"83+ e);84}85}8687/**88* Check reply packet header.89* This method check if reply packet has valid values in the header fields.90*91* @throws PacketFormatException if packet header fields have error or invalid values92*/93/*94protected void checkHeaderForReplyOrEvent() throws PacketFormatException {95super.checkHeader();96}97*/9899/**100* Check reply packet header.101* This method check if reply packet has valid values in the header fields.102*103* @throws PacketFormatException if packet header fields have error or invalid values104*/105public void checkHeader() throws PacketFormatException {106// checkHeaderForReplyOrEvent();107super.checkHeader();108if (getFlags() != JDWP.Flag.REPLY_PACKET) {109throw new PacketFormatException("Unexpected flags in reply packet header: "110+ "0x" + toHexDecString(getFlags(), 2));111}112if (getErrorCode() != JDWP.Error.NONE) {113throw new PacketFormatException("Unexpected error code in reply packet header: "114+ "0x" + toHexDecString(getErrorCode(), 4));115}116}117118/**119* Check reply packet header for specified reply ID.120* This method check if reply packet has valid values in the header fields.121*122* @throws PacketFormatException if packet header fields have error or invalid values123*/124public void checkHeader(int id) throws PacketFormatException {125checkHeader();126if (getPacketID() != id) {127throw new PacketFormatException("Unexpected ID in reply packet header: "128+ getPacketID());129}130}131132/**133* Return string representation of the reply packet header.134*/135public String headerToString() {136String s;137138if (getFlags() == 0)139s = " (command)";140else141s = " (error) ";142143return super.headerToString()144+ " " + toHexString(CommandOffset, 4) + s + ": 0x" + toHexDecString(getErrorCode(), 4) + "\n";145}146147}148149150