Example usage for org.apache.commons.codec.binary StringUtils newStringUtf8

List of usage examples for org.apache.commons.codec.binary StringUtils newStringUtf8

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary StringUtils newStringUtf8.

Prototype

public static String newStringUtf8(final byte[] bytes) 

Source Link

Document

Constructs a new String by decoding the specified array of bytes using the UTF-8 charset.

Usage

From source file:pt.lsts.neptus.util.credentials.Credentials.java

/**
 * @return the (plain) selected login password 
 *//*from   ww w  .  ja  va2s.  c  o m*/
public String getPassword() {
    if (password == null)
        return "";
    return StringUtils.newStringUtf8(DatatypeConverter.parseBase64Binary(password));
}

From source file:vn.chodientu.service.ItemCrawlLogService.java

public DataPage<ItemCrawlLog> search(ItemCrawlLogSearch logSearch) {
    String itemId = logSearch.getItemId();
    String sellerId = logSearch.getSellerId();
    long timeFrom = logSearch.getTimeFrom();
    long timeTo = logSearch.getTimeTo();
    int status = logSearch.getStatus();
    String imgStatus = logSearch.getImageStatus();
    String type = logSearch.getType();
    int pageIndex = logSearch.getPageIndex();
    int pageSize = logSearch.getPageSize();

    Criteria cri = new Criteria();
    if (itemId != null && !itemId.equals("")) {
        cri.and("itemId").is(itemId);
    }//from  ww w .  j a v a2  s.  c  om
    if (sellerId != null && !sellerId.equals("")) {
        cri.and("sellerId").is(sellerId);
    }
    if (imgStatus != null && !imgStatus.equals("")) {
        switch (imgStatus) {
        case "NO_IMAGE":
            cri.and("imageStatus").is(CrawlImageStatus.NO_IMAGE);
            break;
        case "WAIT_DOWNLOAD":
            cri.and("imageStatus").is(CrawlImageStatus.WAIT_DOWNLOAD);
            break;
        case "DOWNLOAD_SUCCESS":
            cri.and("imageStatus").is(CrawlImageStatus.DOWNLOAD_SUCCESS);
            break;
        case "DOWNLOAD_FAIL":
            cri.and("imageStatus").is(CrawlImageStatus.DOWNLOAD_FAIL);
            break;
        case "SMALL_IMAGE":
            cri.and("imageStatus").is(CrawlImageStatus.SMALL_IMAGE);
            break;
        default:
            break;
        }
    }
    if (type != null && !type.equals("")) {
        switch (type) {
        case "ADD":
            cri.and("type").is(CrawlType.ADD);
            break;
        case "EDIT":
            cri.and("type").is(CrawlType.ADD);
            break;
        default:
            break;
        }
    }
    switch (status) {
    case 0: //everrun
        cri.and("status").is(false);
        break;
    case 1: //running
        cri.and("status").is(true);
        break;
    default:
        break;
    }

    if (timeFrom > 0 && timeTo > 0) {
        cri.and("time").gte(timeFrom).lt(timeTo);
    } else if (timeFrom > 0) {
        cri.and("time").gte(timeFrom);
    } else if (timeTo > 0) {
        cri.and("time").lt(timeTo);
    }
    if (pageIndex <= 0) {
        pageIndex = 0;
    }
    if (pageSize <= 0) {
        pageSize = 50;
    }
    Query query = new Query(cri);
    query.skip(pageIndex * pageSize).limit(pageSize);
    query.with(new Sort(Sort.Direction.DESC, "time"));
    //
    DataPage<ItemCrawlLog> dataPage = new DataPage<>();
    dataPage.setData(crawlLogRepository.find(query));
    dataPage.setPageIndex(pageIndex);
    dataPage.setPageSize(pageSize);
    dataPage.setDataCount(crawlLogRepository.count(query));
    dataPage.setPageCount(dataPage.getDataCount() / pageSize);
    try {
        List<String> listItemIds = new ArrayList<>();
        for (ItemCrawlLog crawlLog : dataPage.getData()) {
            if (crawlLog.getItemId() != null && !crawlLog.getItemId().equals("")) {
                listItemIds.add(crawlLog.getItemId());
            }
            List<String> errMsg = new ArrayList<>();
            List<String> alertMsg = new ArrayList<>();
            for (String errcode : crawlLog.getErrorCode()) {
                errMsg.add(ErrorUtils.getErrorMessage(errcode));
            }
            for (String alertCode : crawlLog.getAlertCode()) {
                alertMsg.add(ErrorUtils.getAlertMessage(alertCode));
            }
            crawlLog.setErrorMessage(errMsg);
            crawlLog.setAlertMessage(alertMsg);
        }
        List<Item> listItems = itemService.list(listItemIds);
        for (ItemCrawlLog crawlLog : dataPage.getData()) {
            for (Item item : listItems) {
                if (item.getId().equals(crawlLog.getItemId())) {
                    crawlLog.setItem(item);
                }
            }
            for (KeyVal64 keyval : crawlLog.getRequest()) {
                String value = StringUtils.newStringUtf8(Base64.decodeBase64(keyval.getValue()));
                if (value != null && !value.equals("")) {
                    value = value.trim();
                }
                keyval.setValue(value);
            }
        }
    } catch (Exception ex) {
        return dataPage;
    }
    return dataPage;

}

From source file:yoyo.framework.standard.shared.commons.codec.StringUtilsTest.java

@Test
public void test() {
    String testee = org.apache.commons.lang3.StringUtils.EMPTY;
    assertThat(StringUtils.getBytesUnchecked(testee, "UTF-8"), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesIso8859_1(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesUsAscii(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesUtf8(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesUtf16(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesUtf16Le(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesUtf16Be(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.newString(ArrayUtils.EMPTY_BYTE_ARRAY, "UTF-8"), is(testee));
    assertThat(StringUtils.newStringIso8859_1(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
    assertThat(StringUtils.newStringUsAscii(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
    assertThat(StringUtils.newStringUtf8(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
    assertThat(StringUtils.newStringUtf16(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
    assertThat(StringUtils.newStringUtf16Le(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
    assertThat(StringUtils.newStringUtf16Be(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
}