List of usage examples for java.nio ByteBuffer putChar
public abstract ByteBuffer putChar(char value);
From source file:org.apache.hadoop.yarn.server.nodemanager.containermanager.TestAuxServices.java
@Test public void testAuxEventDispatch() { Configuration conf = new Configuration(); conf.setStrings(YarnConfiguration.NM_AUX_SERVICES, new String[] { "Asrv", "Bsrv" }); conf.setClass(String.format(YarnConfiguration.NM_AUX_SERVICE_FMT, "Asrv"), ServiceA.class, Service.class); conf.setClass(String.format(YarnConfiguration.NM_AUX_SERVICE_FMT, "Bsrv"), ServiceB.class, Service.class); conf.setInt("A.expected.init", 1); conf.setInt("B.expected.stop", 1); final AuxServices aux = new AuxServices(); aux.init(conf);//from ww w . j a v a 2s.co m aux.start(); ApplicationId appId1 = ApplicationId.newInstance(0, 65); ByteBuffer buf = ByteBuffer.allocate(6); buf.putChar('A'); buf.putInt(65); buf.flip(); AuxServicesEvent event = new AuxServicesEvent(AuxServicesEventType.APPLICATION_INIT, "user0", appId1, "Asrv", buf, "user0Folder"); aux.handle(event); ApplicationId appId2 = ApplicationId.newInstance(0, 66); event = new AuxServicesEvent(AuxServicesEventType.APPLICATION_STOP, "user0", appId2, "Bsrv", null, "user0Folder"); // verify all services got the stop event aux.handle(event); Collection<AuxiliaryService> servs = aux.getServices(); for (AuxiliaryService serv : servs) { ArrayList<Integer> appIds = ((LightService) serv).getAppIdsStopped(); assertEquals("app not properly stopped", 1, appIds.size()); assertTrue("wrong app stopped", appIds.contains((Integer) 66)); } for (AuxiliaryService serv : servs) { assertNull(((LightService) serv).containerId); assertNull(((LightService) serv).resource); } ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId1, 1); ContainerTokenIdentifier cti = new ContainerTokenIdentifier(ContainerId.newContainerId(attemptId, 1), "", "", Resource.newInstance(1, 1), 0, 0, 0, Priority.newInstance(0), 0, ""); Context context = mock(Context.class); Container container = new ContainerImpl(null, null, null, null, null, cti, context); ContainerId containerId = container.getContainerId(); Resource resource = container.getResource(); event = new AuxServicesEvent(AuxServicesEventType.CONTAINER_INIT, container); aux.handle(event); for (AuxiliaryService serv : servs) { assertEquals(containerId, ((LightService) serv).containerId); assertEquals(resource, ((LightService) serv).resource); ((LightService) serv).containerId = null; ((LightService) serv).resource = null; } event = new AuxServicesEvent(AuxServicesEventType.CONTAINER_STOP, container); aux.handle(event); for (AuxiliaryService serv : servs) { assertEquals(containerId, ((LightService) serv).containerId); assertEquals(resource, ((LightService) serv).resource); } }
From source file:edu.tsinghua.lumaqq.qq.packets.out._05.TransferPacket.java
@Override protected void putBody(ByteBuffer buf) { if (!requestSend) { // 2. 8/*from w w w . j av a 2 s. c o m*/ buf.putLong(0x0100000000000000L); // 3. session id, 4 buf.putInt(sessionId); // 4 buf.putInt(0); // ?? if (dataReply) { buf.putChar((char) 0x0001); buf.put((byte) 0x02); } else { buf.putChar((char) 0x04); buf.putInt(0); } } else if (data) { // 2. 8??0x1000000000000001? if (last) buf.putLong(0x0100000000000000L); else buf.putLong(0x0100000000000001L); // 3. session id, 4 buf.putInt(sessionId); // 4. 4 buf.putInt(0); // 5. ?2 buf.putChar((char) fragment.length); // 6. ? buf.put(fragment); } else { // 2. 8 buf.putLong(0x0100000000000000L); // 3. session id, 4 buf.putInt(sessionId); // 4. 4 buf.putInt(0); // 5. ???2 buf.putChar((char) 0); // 6. 25? int pos = buf.position(); buf.putChar((char) 0); // 7. md5 buf.put(md5); // 8. ??md5 byte[] fileNameBytes = fileName.getBytes(); buf.put(md5(fileNameBytes)); // 9. 4 buf.putInt(imageLength); // 10. ??2 buf.putChar((char) fileName.length()); // 11. ?? buf.put(fileNameBytes); // 12. 8 buf.putLong(0); char len = (char) (buf.position() - pos); buf.putChar(pos - 2, len); buf.putChar(pos, len); } }
From source file:de.rwhq.btree.InnerNode.java
@Override public void initialize() { if (rawPage().bufferForReading(0).limit() < minPageSize()) { throw new IllegalStateException( "rawPage is too small. It must be at least " + minPageSize() + " bytes."); }/* w w w . j a va 2 s. c o m*/ final ByteBuffer buf = rawPage().bufferForWriting(Header.NODE_TYPE.getOffset()); buf.putChar(NODE_TYPE.serialize()); setNumberOfKeys(0); valid = true; rawPage.sync(); }
From source file:edu.harvard.iq.dvn.core.web.ExploreDataPage.java
private void writeFile(File fileIn, char[] charArrayIn, int bufSize) { try {//from w ww.ja va2s. co m FileOutputStream outputFile = null; outputFile = new FileOutputStream(fileIn, true); FileChannel outChannel = outputFile.getChannel(); ByteBuffer buf = ByteBuffer.allocate((bufSize * 2) + 1000); for (char ch : charArrayIn) { buf.putChar(ch); } buf.flip(); try { outChannel.write(buf); outputFile.close(); } catch (IOException e) { e.printStackTrace(System.err); } } catch (IOException e) { throw new EJBException(e); } }