Example usage for org.apache.commons.lang3 ArrayUtils EMPTY_BYTE_ARRAY

List of usage examples for org.apache.commons.lang3 ArrayUtils EMPTY_BYTE_ARRAY

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ArrayUtils EMPTY_BYTE_ARRAY.

Prototype

null EMPTY_BYTE_ARRAY

To view the source code for org.apache.commons.lang3 ArrayUtils EMPTY_BYTE_ARRAY.

Click Source Link

Document

An empty immutable byte array.

Usage

From source file:com.gargoylesoftware.htmlunit.FailingHttpStatusCodeExceptionTest.java

/**
 * @throws Exception if the test fails/* www.j a  va 2  s .c o  m*/
 */
@Test
public void constructorWithWebResponse() throws Exception {
    final List<NameValuePair> emptyList = Collections.emptyList();
    final WebResponseData webResponseData = new WebResponseData(ArrayUtils.EMPTY_BYTE_ARRAY,
            HttpStatus.SC_NOT_FOUND, "not found", emptyList);
    final WebResponse webResponse = new WebResponse(webResponseData, URL_FIRST, HttpMethod.GET, 10);
    final FailingHttpStatusCodeException e = new FailingHttpStatusCodeException(webResponse);

    assertEquals(webResponse, e.getResponse());
    assertEquals(webResponse.getStatusMessage(), e.getStatusMessage());
    assertEquals(webResponse.getStatusCode(), e.getStatusCode());
    assertTrue("message doesn't contain failing url", e.getMessage().indexOf(URL_FIRST.toExternalForm()) > -1);
}

From source file:de.estudent.nfc.ndef.NdefMessage.java

public byte[] getPayload() {
    byte[] out = ArrayUtils.EMPTY_BYTE_ARRAY;
    for (int i = 0; i < ndefRecords.length - 1; i++) {
        if (ndefRecords[i] == null)
            return out;
        if (out.length == 0)
            out = ndefRecords[i].getPayload();
        else//from   www.ja v a 2 s.c  om
            ArrayUtils.addAll(out, ndefRecords[i].getPayload());
    }
    return out;
}

From source file:com.comcast.viper.flume2storm.event.F2SEvent.java

/**
 * Constructor to build Flume2Storm events
 * /* w w  w .  j a  va  2s .c o  m*/
 * @param headers
 *          See {@link #getHeaders()}. If null, the headers is an empty
 *          immutable map.
 * @param body
 *          See {@link #getBody()}. If null, the payload of the event is an
 *          empty byte array.
 */
public F2SEvent(Map<String, String> headers, byte[] body) {
    if (headers == null) {
        this.headers = ImmutableMap.of();
    } else {
        this.headers = ImmutableMap.copyOf(headers);
    }
    if (body == null) {
        this.body = ArrayUtils.EMPTY_BYTE_ARRAY;
    } else {
        this.body = ArrayUtils.clone(body);
    }
}

From source file:com.gargoylesoftware.htmlunit.WebResponseData.java

/**
 * Constructs without data stream for subclasses that override getBody().
 *
 * @param statusCode        Status code from the server
 * @param statusMessage     Status message from the server
 * @param responseHeaders   Headers in this response
 *///from www .ja  va2s  .co m
protected WebResponseData(final int statusCode, final String statusMessage,
        final List<NameValuePair> responseHeaders) {
    this(ArrayUtils.EMPTY_BYTE_ARRAY, statusCode, statusMessage, responseHeaders);
}

From source file:com.icloud.framework.core.nio.ByteBufferUtil.java

public static ByteBuffer clone(ByteBuffer o) {
    assert o != null;

    if (o.remaining() == 0)
        return ByteBuffer.wrap(ArrayUtils.EMPTY_BYTE_ARRAY);

    ByteBuffer clone = ByteBuffer.allocate(o.remaining());

    if (o.isDirect()) {
        for (int i = o.position(); i < o.limit(); i++) {
            clone.put(o.get(i));//w w w  . ja v a 2 s .c o  m
        }
        clone.flip();
    } else {
        System.arraycopy(o.array(), o.arrayOffset() + o.position(), clone.array(), 0, o.remaining());
    }

    return clone;
}

From source file:cpcc.rv.base.services.RealVehicleStateJobRunnable.java

/**
 * {@inheritDoc}/*from   ww  w . j  a  v  a2  s . c o  m*/
 */
@Override
public void run() {
    HibernateSessionManager sessionManager = serviceResources.getService(HibernateSessionManager.class);
    CommunicationService com = serviceResources.getService(CommunicationService.class);
    RealVehicleRepository rvRepo = serviceResources.getService(RealVehicleRepository.class);

    RealVehicle target = rvRepo.findRealVehicleById(id);

    try {
        CommunicationResponse result = com.transfer(target,
                RealVehicleBaseConstants.REAL_VEHICLE_STATUS_CONNECTOR, ArrayUtils.EMPTY_BYTE_ARRAY);

        RealVehicleState rvState = rvRepo.findRealVehicleStateById(id);
        if (rvState == null) {
            rvState = new RealVehicleState();
            rvState.setId(id);
        }

        String stateString = org.apache.commons.codec.binary.StringUtils.newStringUtf8(result.getContent());
        rvState.setLastUpdate(new Date());
        rvState.setRealVehicleName(target.getName());
        rvState.setState(stateString);

        logger.info("RealVehicleState: ;" + target.getName() + ";" + stateString + ";");

        sessionManager.getSession().saveOrUpdate(rvState);
    } catch (IOException e) {
        logger.debug("Real vehicle state query to " + target.getName() + " did not work. " + e.getMessage());
    }
}

From source file:cpcc.ros.sim.osm.Camera.java

/**
 * @param position the position to capture an image.
 * @return the captured image.//  w w  w.  j a  v  a  2  s.  c  o  m
 * @throws IOException thrown in case of errors.
 */
public byte[] getImage(PolarCoordinate position) throws IOException {
    if (position == null) {
        return ArrayUtils.EMPTY_BYTE_ARRAY;
    }

    PolarCoordinate pos = new PolarCoordinate(position);

    if (pos.getAltitude() > 200) {
        pos.setAltitude(200);
    }

    if (cfg.getOriginPosition() != null) {
        pos = cfg.getGeodeticSystem().walk(cfg.getOriginPosition(), -pos.getLatitude(), pos.getLongitude(),
                pos.getAltitude());
    }

    double dx = pos.getAltitude() * Math.tan(cfg.getCameraApertureAngle() / 2.0);
    double dy = dx * cfg.getCameraHeight() / cfg.getCameraWidth();

    PolarCoordinate topLeftPosition = cfg.getGeodeticSystem().walk(pos, -dy, -dx, 0);
    PolarCoordinate bottomRightPosition = cfg.getGeodeticSystem().walk(pos, dy, dx, 0);

    MercatorProjection newTopLeftTile = new MercatorProjection(cfg.getZoomLevel(),
            topLeftPosition.getLatitude(), topLeftPosition.getLongitude());

    MercatorProjection newBottomRightTile = new MercatorProjection(cfg.getZoomLevel(),
            bottomRightPosition.getLatitude(), bottomRightPosition.getLongitude());

    boolean reloadTiles = topLeftTile == null || !topLeftTile.equalsTile(newTopLeftTile);
    topLeftTile = newTopLeftTile;
    bottomRightTile = newBottomRightTile;

    int newMapWidth = bottomRightTile.getxTile() - topLeftTile.getxTile() + 1;
    int newMapHeight = bottomRightTile.getyTile() - topLeftTile.getyTile() + 1;

    if (newMapWidth > mapWidth || newMapHeight > mapHeight) {
        mapWidth = newMapWidth;
        mapHeight = newMapHeight;
        initMap();
        reloadTiles = true;
    }

    if (reloadTiles) {
        loadTiles();
    }

    return extractImage();
}

From source file:com.github.games647.flexiblelogin.commands.LogoutCommand.java

@Override
public CommandResult execute(CommandSource source, CommandContext args) throws CommandException {
    if (!(source instanceof Player)) {
        source.sendMessage(plugin.getConfigManager().getTextConfig().getPlayersOnlyActionMessage());
        return CommandResult.success();
    }/* w ww . j a  v a 2 s  .  co m*/

    if (plugin.getConfigManager().getConfig().isPlayerPermissions()
            && !source.hasPermission(plugin.getContainer().getId() + ".command.logout")) {
        throw new CommandPermissionException();
    }

    Account account = plugin.getDatabase().getAccountIfPresent((Player) source);
    if (account == null || !account.isLoggedIn()) {
        source.sendMessage(plugin.getConfigManager().getTextConfig().getNotLoggedInMessage());
    } else {
        source.sendMessage(plugin.getConfigManager().getTextConfig().getSuccessfullyLoggedOutMessage());
        account.setLoggedIn(false);
        account.setIp(ArrayUtils.EMPTY_BYTE_ARRAY);

        plugin.getGame().getScheduler().createTaskBuilder().async().execute(() -> {
            //flushes the ip update
            plugin.getDatabase().save(account);
            if (plugin.getConfigManager().getConfig().isUpdateLoginStatus()) {
                plugin.getDatabase().flushLoginStatus(account, false);
            }
        }).submit(plugin);
    }

    return CommandResult.success();
}

From source file:cpcc.rv.base.services.RealVehicleStateJobRunnableTest.java

@Test
public void shouldHandleExistingRvState() throws ClientProtocolException, IOException {
    when(com.transfer(rv, RealVehicleBaseConstants.REAL_VEHICLE_STATUS_CONNECTOR, ArrayUtils.EMPTY_BYTE_ARRAY))
            .thenReturn(response);/*from ww w . j av  a  2s  .  co m*/

    RealVehicleState rvState = mock(RealVehicleState.class);
    when(rvRepo.findRealVehicleStateById(RV_ID)).thenReturn(rvState);

    Date now = new Date();
    sut.run();

    ArgumentCaptor<Date> captor = ArgumentCaptor.forClass(Date.class);
    verify(rvState).setLastUpdate(captor.capture());
    Date value = captor.getValue();
    assertThat(value.getTime() - now.getTime()).isLessThan(1000L);

    verify(rvState).setRealVehicleName(rv.getName());
    verify(rvState).setState(RESPONSE_STRING);
    verifyNoMoreInteractions(rvState);

    verify(session).saveOrUpdate(rvState);
    verify(logger).info(matches("RealVehicleState: ;.*"));
}

From source file:cpcc.rv.base.services.RealVehicleStateJobRunnableTest.java

@Test
public void shouldHandleMissingRvState() throws ClientProtocolException, IOException {
    when(com.transfer(rv, RealVehicleBaseConstants.REAL_VEHICLE_STATUS_CONNECTOR, ArrayUtils.EMPTY_BYTE_ARRAY))
            .thenReturn(response);/*from   www  . ja  v  a2s .  c  om*/

    Date now = new Date();
    sut.run();

    ArgumentCaptor<RealVehicleState> captor = ArgumentCaptor.forClass(RealVehicleState.class);

    verify(session).saveOrUpdate(captor.capture());

    RealVehicleState rvState = captor.getValue();
    assertThat(rvState.getId()).isEqualTo(rv.getId());
    assertThat(rvState.getLastUpdate().getTime() - now.getTime()).isLessThan(1000);
    assertThat(rvState.getRealVehicleName()).isEqualTo(rv.getName());
    assertThat(rvState.getState()).isEqualTo(RESPONSE_STRING);

    verify(logger).info(matches("RealVehicleState: ;.*"));
}