datagramsocketcommserviceutils.java
来自「cqME :java framework for TCK test.」· Java 代码 · 共 135 行
JAVA
135 行
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.j2me.services.commService;/** * Base utility class for DatagramSocket based plugins to DTF. * Used by classes: * com.sun.tck.j2me.services.commService.servers.DatagramSocketCommServer * com.sun.tck.j2me.services.commService.clients.DatagramSocketCommClient */public class DatagramSocketCommServiceUtils { // Shared constants protected static final int DEFAULT_PACKET_SIZE = 4 * 1024; // 4kb limit by default protected static final int DEFAULT_SOCKET_TIMEOUT = 5000; // 5 seconds // init method options constants protected static final String VERBOSE_OPTION = "verbose="; protected static final String SOCKET_TIMEOUT_OPTION = "socketTimeout="; protected static final String PACKET_SIZE_OPTION = "packetSize="; protected boolean verbose = false; protected int socketTimeout = DEFAULT_SOCKET_TIMEOUT; protected int packetSize = DEFAULT_PACKET_SIZE; // Error messages private static final String errorIncorrectSocketTimeout = "DatagramSocketCommServiceUtils.processArg: Incorrect socket " + "timeout specified: "; private static final String errorIncorrectPacketSize = "DatagramSocketCommServiceUtils.processArg: Incorrect packet " + "size specified: "; private static final String errorUnrecArg = "DatagramSocketCommServiceUtils.processArg: Unrecognized argument: \""; public DatagramSocketCommServiceUtils() { // do not need to do anything here because // variables are already initialized }/* -------------------- protected stuff below this line --------------------*/ protected void verboseln(String str) { if (verbose) { System.out.println(str); } } protected void verbosetrace(Throwable t) { if (verbose) { t.printStackTrace(); } } public void decodeAllArgs(String[] args) { verboseln("DatagramSocketCommServiceUtils.decodeAllArgs: " + "number of args " + args.length); for (int i = 0; i < args.length; i++) { verboseln("args[" + i + "] " + args[i]); processArg(args[i]); } } protected void processArg(String arg) { if (arg.startsWith(VERBOSE_OPTION)) { if (arg.length() > VERBOSE_OPTION.length()) { verbose = new Boolean( arg.substring(VERBOSE_OPTION.length())).booleanValue(); } else { verbose = false; } } else if (arg.startsWith(SOCKET_TIMEOUT_OPTION) && arg.length() > SOCKET_TIMEOUT_OPTION.length()) { String socketTimeoutString = arg.substring(SOCKET_TIMEOUT_OPTION.length()); try { socketTimeout = Integer.parseInt(socketTimeoutString); } catch (NumberFormatException nfe) { throw new IllegalArgumentException(errorIncorrectSocketTimeout + socketTimeoutString); } if (socketTimeout < 1) { throw new IllegalArgumentException(errorIncorrectSocketTimeout + socketTimeoutString); } } else if (arg.startsWith(PACKET_SIZE_OPTION) && arg.length() > PACKET_SIZE_OPTION.length()) { String packetSizeString = arg.substring(PACKET_SIZE_OPTION.length()); try { packetSize = Integer.parseInt(packetSizeString); } catch (NumberFormatException nfe) { throw new IllegalArgumentException(errorIncorrectPacketSize + packetSizeString); } if (packetSize < 1) { throw new IllegalArgumentException(errorIncorrectPacketSize + packetSizeString); } } else { throw new IllegalArgumentException(errorUnrecArg + arg + "\""); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?