List of usage examples for org.apache.commons.lang ArrayUtils subarray
public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new boolean
array containing the elements between the start and end indices.
From source file:org.openhab.binding.zigbee.internal.protocol.SerialMessage.java
/** * Constructor. Creates a new instance of the SerialMessage class from a * specified buffer, and subsequently sets the node ID. * @param nodeId the node the message is destined for * @param buffer the buffer to create the SerialMessage from. *///from w w w. j a v a2 s . c om public SerialMessage(int nodeId, byte[] buffer) { logger.trace("NODE {}: Creating new SerialMessage from buffer = {}", nodeId, SerialMessage.bb2hex(buffer)); messageLength = buffer.length - 2; // buffer[1]; byte messageCheckSumm = calculateChecksum(buffer); byte messageCheckSummReceived = buffer[messageLength + 1]; logger.trace(String.format("NODE %d: Message checksum calculated = 0x%02X, received = 0x%02X", nodeId, messageCheckSumm, messageCheckSummReceived)); if (messageCheckSumm == messageCheckSummReceived) { logger.trace("NODE {}: Checksum matched", nodeId); isValid = true; } else { logger.trace("NODE {}: Checksum error", nodeId); isValid = false; return; } this.messageType = buffer[2] == 0x00 ? SerialMessageType.Request : SerialMessageType.Response; ; this.messageClass = SerialMessageClass.getMessageClass(buffer[3] & 0xFF); this.messagePayload = ArrayUtils.subarray(buffer, 4, messageLength + 1); this.messageNode = nodeId; logger.trace("NODE {}: Message payload = {}", getMessageNode(), SerialMessage.bb2hex(messagePayload)); }
From source file:org.openhab.binding.zwave.internal.protocol.serialmessage.GetVersionMessageClass.java
@Override public boolean handleResponse(ZWaveController zController, SerialMessage lastSentMessage, SerialMessage incomingMessage) { ZWaveLibraryType = incomingMessage.getMessagePayloadByte(12); zWaveVersion = new String(ArrayUtils.subarray(incomingMessage.getMessagePayload(), 0, 11)); logger.debug(String.format("Got MessageGetVersion response. Version = %s, Library Type = 0x%02X", zWaveVersion, ZWaveLibraryType)); checkTransactionComplete(lastSentMessage, incomingMessage); return true;/*from w w w . j a v a2s. c om*/ }
From source file:org.openhab.binding.zwave.internal.protocol.SerialMessage.java
/** * Constructor. Creates a new instance of the SerialMessage class from a * specified buffer, and subsequently sets the node ID. * @param nodeId the node the message is destined for * @param buffer the buffer to create the SerialMessage from. *///from w w w . j a v a 2s. c om public SerialMessage(int nodeId, byte[] buffer) { logger.trace("NODE {}: Creating new SerialMessage from buffer = {}", nodeId, SerialMessage.bb2hex(buffer)); messageLength = buffer.length - 2; // buffer[1]; byte messageCheckSumm = calculateChecksum(buffer); byte messageCheckSummReceived = buffer[messageLength + 1]; if (messageCheckSumm == messageCheckSummReceived) { logger.trace("NODE {}: Checksum matched", nodeId); isValid = true; } else { logger.trace("NODE {}: Checksum error. Calculated = 0x%02X, Received = 0x%02X", nodeId, messageCheckSumm, messageCheckSummReceived); isValid = false; return; } this.priority = SerialMessagePriority.High; this.messageType = buffer[2] == 0x00 ? SerialMessageType.Request : SerialMessageType.Response; this.messageClass = SerialMessageClass.getMessageClass(buffer[3] & 0xFF); this.messagePayload = ArrayUtils.subarray(buffer, 4, messageLength + 1); this.messageNode = nodeId; logger.trace("NODE {}: Message payload = {}", getMessageNode(), SerialMessage.bb2hex(messagePayload)); }
From source file:org.openhab.binding.zwave.internal.protocol.ZWaveController.java
/** * Handles the response of the getVersion request. * @param incomingMessage the response message to process. *//* w w w.jav a 2 s . com*/ private void handleGetVersionResponse(SerialMessage incomingMessage) { this.ZWaveLibraryType = incomingMessage.getMessagePayloadByte(12); this.zWaveVersion = new String(ArrayUtils.subarray(incomingMessage.getMessagePayload(), 0, 11)); logger.debug(String.format("Got MessageGetVersion response. Version = %s, Library Type = 0x%02X", zWaveVersion, ZWaveLibraryType)); }
From source file:org.opentestsystem.shared.security.service.AbsractRolesAndPermissionsService.java
protected Multimap<String, SbacRole> extractUserRoles(final String pipeDelimitedTenancyChain, final Map<String, RoleToPermissionMapping> roleToPermissionMappings) { List<String[]> roleStringsDelimited = new ArrayList<String[]>(); LOGGER.debug("tenantChain: " + pipeDelimitedTenancyChain); if (StringUtils.isNotEmpty(pipeDelimitedTenancyChain)) { final String[] attr = pipeDelimitedTenancyChain.split("[|]", -1); // split one long string into individual rows for parsing final int roleCount = attr.length / ROLE_FIELD_COUNT; for (int i = 0; i < roleCount; i++) { final Object[] roleStringSet = ArrayUtils.subarray(attr, i * ROLE_FIELD_COUNT, (i + 1) * ROLE_FIELD_COUNT); roleStringsDelimited.add((String[]) roleStringSet); }/* ww w.ja v a 2 s . c o m*/ } final Multimap<String, SbacRole> userRoles = buildRolesFromParsedStrings(roleToPermissionMappings, roleStringsDelimited); setupEffectiveTenantsForRoles(Lists.newArrayList(userRoles.values())); return userRoles; }
From source file:org.ow2.chameleon.fuchsia.importer.zwave.internal.protocol.SerialMessage.java
/** * Constructor. Creates a new instance of the SerialMessage class from a * specified buffer, and subsequently sets the node ID. * @param nodeId the node the message is destined for * @param buffer the buffer to create the SerialMessage from. *///from www. j a v a2 s. c o m public SerialMessage(int nodeId, byte[] buffer) { logger.debug("Creating new SerialMessage from buffer = " + SerialMessage.bb2hex(buffer)); messageLength = buffer.length - 2; // buffer[1]; byte messageCheckSumm = calculateChecksum(buffer); byte messageCheckSummReceived = buffer[messageLength + 1]; logger.debug(String.format("Message checksum calculated = 0x%02X, received = 0x%02X", messageCheckSumm, messageCheckSummReceived)); if (messageCheckSumm == messageCheckSummReceived) { logger.trace("Checksum matched"); isValid = true; } else { logger.trace("Checksum error"); isValid = false; return; } this.messageType = buffer[2] == 0x00 ? SerialMessageType.Request : SerialMessageType.Response; ; this.messageClass = SerialMessageClass.getMessageClass(buffer[3] & 0xFF); this.messagePayload = ArrayUtils.subarray(buffer, 4, messageLength + 1); this.messageNode = nodeId; logger.debug("Message Node ID = " + getMessageNode()); logger.debug("Message payload = " + SerialMessage.bb2hex(messagePayload)); }
From source file:org.owasp.jbrofuzz.headers.HeaderLoader.java
/** * <p>/* ww w .jav a 2 s.c om*/ * Private, recursive method used at construction to populate the master * <code>HeaderTreeNode</code> that can be accessed via the * <code>getMasterTreeNode</code> method. * </p> * <p> * In accessing this method, do not forget to reset the * <code>globalCounter</code> as if it reaches a value of * <code>MAX_RECURSION * </code> this method will simply return. * </p> * * @param categoriesArray * The array of nodes to be added. * @param headerTreeNode * The tree node on which to be added. * * @see #getMasterHeader() * @author subere@uncon.org * @version 1.3 * @since 1.2 */ private void addNodes(final String[] categoriesArray, final HeaderTreeNode headerTreeNode) { if (categoriesArray.length == 0) { return; } if (globalCounter > MAX_RECURSION) { return; } globalCounter++; // Find the first element final String firstElement = StringUtils.stripStart(StringUtils.stripEnd(categoriesArray[0], " "), " "); // Use the index to know its position int index = 0; boolean exists = false; for (final Enumeration<HeaderTreeNode> e = extracted(headerTreeNode); e.hasMoreElements() && !exists;) { final String currentElement = e.nextElement().toString(); if (currentElement.equalsIgnoreCase(firstElement)) { exists = true; } else { // If firstElement not current, increment index++; } } // Does the first element exist? if (!exists) { headerTreeNode.add(new HeaderTreeNode(firstElement)); } // Remove the first element, start again final String[] temp = (String[]) ArrayUtils.subarray(categoriesArray, 1, categoriesArray.length); final HeaderTreeNode nemp = (HeaderTreeNode) headerTreeNode.getChildAt(index); addNodes(temp, nemp); }
From source file:org.parancoe.util.MemoryAppender.java
public static String getLastNLines(int n) { String[] lines = StringUtils.split(getFullLog(), '\n'); if (lines.length <= n) return getFullLog(); String[] interestingLines = (String[]) ArrayUtils.subarray(lines, lines.length - n, lines.length); return StringUtils.join(interestingLines, '\n'); }
From source file:org.quackbot.hooks.core.CoreQuackbotListener.java
protected String executeOnCommandLong(CommandEvent commandEvent) throws Exception { try {/*from w w w .j a va 2 s.c o m*/ Command command = commandEvent.getCommandClass(); Class clazz = command.getClass(); for (Method curMethod : clazz.getMethods()) if (curMethod.getName().equalsIgnoreCase("onCommand") && curMethod.getParameterTypes().length != 1) { //Get parameters leaving off the first one Class[] parameters = (Class[]) ArrayUtils.remove(curMethod.getParameterTypes(), 0); Object[] args = new Object[0]; String[] userArgs = commandEvent.getArgs(); log.debug("UserArgs: " + StringUtils.join(userArgs, ", ")); //Try and fill argument list, handling arrays for (int i = 0; i < userArgs.length; i++) { log.trace("Current parameter: " + i); if (i < parameters.length && parameters[i].isArray()) { log.trace("Parameter " + i + " is an array"); //Look ahead to see how big of an array we need int arrayLength = parameters.length - (i - 1); for (int s = i; s < parameters.length; s++) if (!parameters[s].isArray()) arrayLength--; //Add our array of specified length log.trace("Parameter " + i + " is an array. Assigning it the next " + arrayLength + " args"); Object[] curArray = ArrayUtils.subarray(userArgs, i, i + arrayLength); args = ArrayUtils.add(args, curArray); log.trace("Parameter " + i + " set to " + StringUtils.join(curArray, ", ")); //Move the index forward to account for the args folded into the array i += arrayLength - 1; } else { log.trace("User arg " + i + " isn't an array, assigning " + userArgs[i]); args = ArrayUtils.add(args, userArgs[i]); } } //Pad the args with null values args = Arrays.copyOf(args, parameters.length); //Prefix with command event args = ArrayUtils.addAll(new Object[] { commandEvent }, args); log.trace("Args minus CommandEvent: " + StringUtils.join(ArrayUtils.remove(args, 0), ", ")); //Execute method return (String) curMethod.invoke(command, args); } } catch (InvocationTargetException e) { //Unrwap if nessesary Throwable cause = e.getCause(); if (cause != null && cause instanceof Exception) throw (Exception) e.getCause(); throw e; } return null; }
From source file:org.restcomm.sbc.media.MediaZone.java
public byte[] encodeRTP(byte[] data, int offset, int length) { /*/* ww w. j a v a2 s . c o m*/ if(LOG.isTraceEnabled()) { LOG.trace("VOID Decoding "+length+" bytes"); } */ return ArrayUtils.subarray(data, offset, length); }