List of usage examples for java.lang Integer byteValue
public byte byteValue()
From source file:org.uribeacon.beacon.UriBeaconTest.java
public void testUriBeaconTestData() throws JSONException, IOException { Context context = getContext(); AssetManager am = context.getAssets(); JSONObject testObject = inputJson(am.open("testdata.json")); JSONArray testData = testObject.getJSONArray("test-data"); for (int i = 0; i < testData.length(); i++) { JSONObject encodingTest = testData.getJSONObject(i); String uri = encodingTest.getString("url"); assertNotNull(uri);/*from ww w. java 2 s . co m*/ Integer txPowerLevel = encodingTest.optInt("tx", 20); Integer flags = encodingTest.optInt("flags", 0); UriBeacon uriBeacon; try { uriBeacon = new UriBeacon.Builder().uriString(uri).txPowerLevel(txPowerLevel.byteValue()) .flags(flags.byteValue()).build(); } catch (URISyntaxException e) { uriBeacon = null; } JSONArray scanRecordJson = encodingTest.optJSONArray("scanRecord"); if (scanRecordJson == null || uriBeacon == null) { assertNull("Null assert failed for uriBeacon", scanRecordJson); assertNull("Null assert failed for " + uriBeacon, uriBeacon); } else { byte[] scanRecord = jsonToByteArray(scanRecordJson); byte[] uriBeaconScanRecord = uriBeacon.toByteArray(); MoreAsserts.assertEquals(scanRecord, uriBeaconScanRecord); } } }
From source file:com.intuit.tank.api.model.v1.datafile.DataFileDescriptorTest.java
/** * Run the Integer getId() method test./*from w ww. j av a 2 s . com*/ * * @throws Exception * * @generatedBy CodePro at 12/15/14 3:00 PM */ @Test public void testGetId_1() throws Exception { DataFileDescriptor fixture = new DataFileDescriptor(); fixture.setComments(""); fixture.setCreator(""); fixture.setName(""); fixture.setDataUrl(""); fixture.setId(new Integer(1)); fixture.setCreated(new Date()); fixture.setModified(new Date()); Integer result = fixture.getId(); assertNotNull(result); assertEquals("1", result.toString()); assertEquals((byte) 1, result.byteValue()); assertEquals((short) 1, result.shortValue()); assertEquals(1, result.intValue()); assertEquals(1L, result.longValue()); assertEquals(1.0f, result.floatValue(), 1.0f); assertEquals(1.0, result.doubleValue(), 1.0); }
From source file:com.jaspersoft.jasperserver.ws.axis2.repository.ReportUnitHandler.java
protected void updateResource(Resource resource, ResourceDescriptor descriptor, RepositoryServiceContext serviceContext) throws WSException { ReportUnit reportUnit = (ReportUnit) resource; Boolean alwaysPrompt = descriptor .getResourcePropertyValueAsBoolean(ResourceDescriptor.PROP_RU_ALWAYS_PROPMT_CONTROLS); if (alwaysPrompt != null) { reportUnit.setAlwaysPromptControls(alwaysPrompt.booleanValue()); }//w w w . jav a2 s . com Integer controlsLayout = descriptor .getResourcePropertyValueAsInteger(ResourceDescriptor.PROP_RU_CONTROLS_LAYOUT); if (controlsLayout != null) { reportUnit.setControlsLayout(controlsLayout.byteValue()); } String controlsView = descriptor .getResourcePropertyValue(ResourceDescriptor.PROP_RU_INPUTCONTROL_RENDERING_VIEW); if (controlsView != null) reportUnit.setInputControlRenderingView(controlsView); String renderingView = descriptor .getResourcePropertyValue(ResourceDescriptor.PROP_RU_REPORT_RENDERING_VIEW); if (renderingView != null) reportUnit.setReportRenderingView(renderingView); List children = descriptor.getChildren(); for (int i = 0; i < children.size(); ++i) { ResourceDescriptor childResource = (ResourceDescriptor) children.get(i); if (serviceContext.getHandlerRegistry().typeExtends(childResource.getWsType(), ResourceDescriptor.TYPE_DATASOURCE)) { if (childResource.getIsReference()) { reportUnit.setDataSourceReference(childResource.getReferenceUri()); } else { ReportDataSource dataSource = (ReportDataSource) toChildResource(childResource, serviceContext); reportUnit.setDataSource(dataSource); } } else if (childResource.getWsType().equals(ResourceDescriptor.TYPE_JRXML) && childResource.isMainReport()) { String referenceURI = childResource.getReferenceUri(); if (referenceURI != null && referenceURI.trim().length() > 0) { reportUnit.setMainReportReference(referenceURI); } else { FileResource fileResource = (FileResource) toChildResource(childResource, serviceContext); fileResource.setFileType(FileResource.TYPE_JRXML); reportUnit.setMainReport(fileResource); } } } }
From source file:com.codestation.henkakuserver.HenkakuServer.java
private Pair<ArrayList<Integer>, List<Byte>> preprocessRop(byte[] urop) throws Exception { byte[] loader = new byte[urop.length + ((-urop.length) & 3)]; System.arraycopy(urop, 0, loader, 0, urop.length); ByteBuffer buf = ByteBuffer.wrap(loader).order(ByteOrder.LITTLE_ENDIAN); int header_size = 0x40; int dsize = buf.getInt(0x10); int csize = buf.getInt(0x20); int reloc_size = buf.getInt(0x30); int symtab_size = buf.getInt(0x38); if (csize % 4 != 0) { throw new Exception("csize % 4 != 0???"); }/*w w w . j a v a 2 s. c om*/ int reloc_offset = header_size + dsize + csize; int symtab = reloc_offset + reloc_size; int symtab_n = symtab_size / 8; Map<Integer, String> reloc_map = new HashMap<>(); for (int x = 0; x < symtab_n; ++x) { int sym_id = buf.getInt(symtab + 8 * x); int str_offset = buf.getInt(symtab + 8 * x + 4); int end = str_offset; while (loader[end] != 0) { end += 1; } String name = new String(Arrays.copyOfRange(loader, str_offset, end)); reloc_map.put(sym_id, name); } Map<Pair<String, Integer>, Integer> reloc_type_map = new HashMap<>(); reloc_type_map.put(new Pair<>("rop.data", 0), 1); reloc_type_map.put(new Pair<>("SceWebKit", 0), 2); reloc_type_map.put(new Pair<>("SceLibKernel", 0), 3); reloc_type_map.put(new Pair<>("SceLibc", 0), 4); reloc_type_map.put(new Pair<>("SceLibHttp", 0), 5); reloc_type_map.put(new Pair<>("SceNet", 0), 6); reloc_type_map.put(new Pair<>("SceAppMgr", 0), 7); int want_len = 0x40 + dsize + csize; ArrayList<Integer> urop_js = new ArrayList<>(); byte[] relocs = new byte[want_len / 4]; int reloc_n = reloc_size / 8; for (int x = 0; x < reloc_n; ++x) { int reloc_type = buf.getShort(reloc_offset + 8 * x); int sym_id = buf.getShort(reloc_offset + 8 * x + 2); int offset = buf.getInt(reloc_offset + 8 * x + 4); if (offset % 4 != 0) { throw new Exception("offset % 4 != 0???"); } if (relocs[offset / 4] != 0) { throw new Exception("symbol relocated twice, not supported"); } Integer wk_reloc_type = reloc_type_map.get(new Pair<>(reloc_map.get(sym_id), reloc_type)); if (wk_reloc_type == null) { throw new Exception("unsupported relocation type"); } relocs[offset / 4] = wk_reloc_type.byteValue(); } for (int x = 0; x < want_len; x += 4) { urop_js.add(buf.getInt(x)); } List<Byte> relocsArray = Arrays.asList(ArrayUtils.toObject(relocs)); return new Pair<>(urop_js, relocsArray); }
From source file:com.jaspersoft.jasperserver.remote.handlers.ReportUnitHandler.java
/** * * The updateResource method for the report unit just set basic options of the report unit and check for a datasource, * the main jrxml and if available the main query. * * * @param resource//from w w w .ja va2 s . c o m * @param descriptor * @param options * @throws ServiceException */ @Override public void updateResource(Resource resource, ResourceDescriptor descriptor, Map options) throws ServiceException { super.updateResource(resource, descriptor, options); ReportUnit reportUnit = (ReportUnit) resource; Boolean alwaysPrompt = descriptor .getResourcePropertyValueAsBoolean(ResourceDescriptor.PROP_RU_ALWAYS_PROPMT_CONTROLS); if (alwaysPrompt != null) { reportUnit.setAlwaysPromptControls(alwaysPrompt.booleanValue()); } Integer controlsLayout = descriptor .getResourcePropertyValueAsInteger(ResourceDescriptor.PROP_RU_CONTROLS_LAYOUT); if (controlsLayout != null) { reportUnit.setControlsLayout(controlsLayout.byteValue()); } String controlsView = descriptor .getResourcePropertyValue(ResourceDescriptor.PROP_RU_INPUTCONTROL_RENDERING_VIEW); if (controlsView != null) { reportUnit.setInputControlRenderingView(controlsView); } String renderingView = descriptor .getResourcePropertyValue(ResourceDescriptor.PROP_RU_REPORT_RENDERING_VIEW); if (renderingView != null) { reportUnit.setReportRenderingView(renderingView); } List children = descriptor.getChildren(); for (int i = 0; i < children.size(); ++i) { ResourceDescriptor childResource = (ResourceDescriptor) children.get(i); if (isDataSource(childResource)) { if (childResource.getIsReference()) { reportUnit.setDataSourceReference(childResource.getReferenceUri()); } else { ReportDataSource dataSource = (ReportDataSource) createChildResource(childResource); reportUnit.setDataSource(dataSource); } } else if (ResourceDescriptor.isFileType(childResource.getWsType()) || childResource.getWsType().equals(ResourceDescriptor.TYPE_REFERENCE)) { if (childResource.isMainReport()) { String referenceURI = childResource.getReferenceUri(); if (referenceURI != null && referenceURI.trim().length() > 0) { reportUnit.setMainReportReference(referenceURI); } else { FileResource fileResource = (FileResource) createChildResource(childResource); fileResource.setFileType(childResource.getWsType()); reportUnit.setMainReport(fileResource); } } else { FileResource fileResource = (FileResource) createChildResource(childResource); reportUnit.addResource(fileResource); } } else if (childResource.getWsType().equals(ResourceDescriptor.TYPE_INPUT_CONTROL)) { String referenceURI = childResource.getReferenceUri(); if (referenceURI != null && referenceURI.trim().length() > 0) { reportUnit.addInputControlReference(referenceURI); } else { InputControl ic = (InputControl) createChildResource(childResource); reportUnit.addInputControl(ic); } } } }
From source file:de.unibayreuth.bayeos.goat.table.MassenTableModel.java
public boolean addRow(ObjektNode objektNode, Vector values) { boolean bol = false; try {/*from w w w .j av a 2 s .co m*/ // Update display values java.util.Date von = (java.util.Date) values.elementAt(0); Double wert = (Double) values.elementAt(1); Integer status = (Integer) values.elementAt(2); Vector params = new Vector(); params.add(objektNode.getId()); params.add(von); params.add(wert); params.add(status); bol = ((Boolean) xmlClient.execute("MassenTableHandler.addRow", params)).booleanValue(); vonList.add((int) (von.getTime() / 1000)); wertList.add(wert.doubleValue()); statusList.add(status.byteValue()); fireTableDataChanged(); } catch (XmlRpcException x) { MsgBox.error(x.getMessage()); return false; } return bol; }
From source file:ee.sk.digidoc.SignedDoc.java
/** * Converts a hex string to byte array/*w w w .ja v a2 s . co m*/ * @param hexString input data * @return byte array */ public static byte[] hex2bin(String hexString) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { for (int i = 0; (hexString != null) && (i < hexString.length()); i += 2) { String tmp = hexString.substring(i, i + 2); Integer x = new Integer(Integer.parseInt(tmp, 16)); bos.write(x.byteValue()); } } catch (Exception ex) { m_logger.error("Error converting hex string: " + ex); } return bos.toByteArray(); }
From source file:org.openhab.binding.max.internal.command.M_Command.java
@Override public String getCommandString() { int deviceCount = 0; int roomCount = 0; ByteArrayOutputStream message = new ByteArrayOutputStream(); try {/*from www . ja v a2 s. c om*/ byte[] header = { MAGIC_NR, M_VERSION, (byte) rooms.size() }; message.write(header); TreeSet<Integer> sortedRooms = new TreeSet<Integer>(); for (RoomInformation room : rooms) { sortedRooms.add(room.getPosition()); } for (Integer roomPos : sortedRooms) { for (RoomInformation room : rooms) { if (room.getPosition() == roomPos) { if (roomCount < MAX_GROUP_COUNT) { byte[] roomName = StringUtils.abbreviate(room.getName(), MAX_NAME_LENGTH) .getBytes("UTF-8"); byte[] nameLength = new byte[] { (byte) roomName.length }; byte[] rfAddress = Utils.hexStringToByteArray(room.getRFAddress()); message.write(roomPos.byteValue()); message.write(nameLength); message.write(roomName); message.write(rfAddress); } else { logger.warn("{} exceeds max number of rooms ({}). Ignored", room.toString(), MAX_GROUP_COUNT); } roomCount++; } } } for (Device di : devices) { if (deviceCount < MAX_DEVICES_COUNT) { deviceCount++; } else { logger.warn("{} exceeds max number of devices ({}). Ignored", di.toString(), MAX_DEVICES_COUNT); } } message.write((byte) deviceCount); for (Device di : devices) { if (deviceCount > 0) { byte[] deviceType = { (byte) di.getType().getValue() }; byte[] rfAddress = Utils.hexStringToByteArray(di.getRFAddress()); byte[] deviceName = StringUtils.abbreviate(di.getName(), MAX_NAME_LENGTH).getBytes("UTF-8"); byte[] nameLength = { (byte) deviceName.length }; byte[] serialNumber = di.getSerialNumber().getBytes(); byte[] roomId = { (byte) di.getRoomId() }; message.write(deviceType); message.write(rfAddress); message.write(serialNumber); message.write(nameLength); message.write(deviceName); message.write(roomId); } else { logger.warn("{} exceeds max number of devices ({}). Ignored", di.toString(), MAX_DEVICES_COUNT); } deviceCount--; } byte[] dst = { 0x01 }; message.write(dst); } catch (IOException e) { logger.debug("Error while generating m: command: {}", e.getMessage(), e); } String encodedString = Base64.encodeBase64StringUnChunked(message.toByteArray()); String commandString = ""; int parts = (int) Math.round(encodedString.length() / MAX_MSG_LENGTH + 0.5); for (int i = 0; i < parts; i++) { String partString = StringUtils.abbreviate(encodedString.substring((i) * MAX_MSG_LENGTH), MAX_MSG_LENGTH); commandString = commandString + "m:" + String.format("%02d", i) + "," + partString + '\r' + '\n'; } return commandString; }
From source file:org.openhab.binding.max.internal.command.MCommand.java
@Override public String getCommandString() { int deviceCount = 0; int roomCount = 0; ByteArrayOutputStream message = new ByteArrayOutputStream(); try {// ww w . j av a2 s. co m byte[] header = { MAGIC_NR, M_VERSION, (byte) rooms.size() }; message.write(header); Set<Integer> sortedRooms = new TreeSet<>(); for (RoomInformation room : rooms) { sortedRooms.add(room.getPosition()); } for (Integer roomPos : sortedRooms) { for (RoomInformation room : rooms) { if (room.getPosition() == roomPos) { if (roomCount < MAX_GROUP_COUNT) { byte[] roomName = StringUtils.abbreviate(room.getName(), MAX_NAME_LENGTH) .getBytes(StandardCharsets.UTF_8); byte[] nameLength = new byte[] { (byte) roomName.length }; byte[] rfAddress = Utils.hexStringToByteArray(room.getRFAddress()); message.write(roomPos.byteValue()); message.write(nameLength); message.write(roomName); message.write(rfAddress); } else { logger.warn("{} exceeds max number of rooms ({}). Ignored", room, MAX_GROUP_COUNT); } roomCount++; } } } for (Device di : devices) { if (deviceCount < MAX_DEVICES_COUNT) { deviceCount++; } else { logger.warn("{} exceeds max number of devices ({}). Ignored", di, MAX_DEVICES_COUNT); } } message.write((byte) deviceCount); for (Device di : devices) { if (deviceCount > 0) { byte[] deviceType = { (byte) di.getType().getValue() }; byte[] rfAddress = Utils.hexStringToByteArray(di.getRFAddress()); byte[] deviceName = StringUtils.abbreviate(di.getName(), MAX_NAME_LENGTH) .getBytes(StandardCharsets.UTF_8); byte[] nameLength = { (byte) deviceName.length }; byte[] serialNumber = di.getSerialNumber().getBytes(StandardCharsets.UTF_8); byte[] roomId = { (byte) di.getRoomId() }; message.write(deviceType); message.write(rfAddress); message.write(serialNumber); message.write(nameLength); message.write(deviceName); message.write(roomId); } else { logger.warn("{} exceeds max number of devices ({}). Ignored", di, MAX_DEVICES_COUNT); } deviceCount--; } byte[] dst = { 0x01 }; message.write(dst); } catch (IOException e) { logger.debug("Error while generating m: command: {}", e.getMessage(), e); } final String encodedString = Base64.encodeBase64StringUnChunked(message.toByteArray()); final StringBuilder commandStringBuilder = new StringBuilder(); int parts = (int) Math.round(encodedString.length() / MAX_MSG_LENGTH + 0.5); for (int i = 0; i < parts; i++) { String partString = StringUtils.abbreviate(encodedString.substring((i) * MAX_MSG_LENGTH), MAX_MSG_LENGTH); commandStringBuilder.append("m:").append(String.format("%02d", i)).append(",").append(partString) .append('\r').append('\n'); } return commandStringBuilder.toString(); }