Skip to content

Instantly share code, notes, and snippets.

@hn5092
Created April 10, 2017 09:05
Show Gist options
  • Save hn5092/dba7da0e9afd7743105c8f4d033ccab7 to your computer and use it in GitHub Desktop.
Save hn5092/dba7da0e9afd7743105c8f4d033ccab7 to your computer and use it in GitHub Desktop.
package com.pajk.bigdata.flink.utils;
import org.apache.hadoop.hbase.util.Bytes;
import org.testng.annotations.Test;
import org.testng.collections.Lists;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
/**
* Created by imad on 10/04/2017.
*/
public class MyTriggerTest {
@Test
public void testRead() throws IOException {
List<String> processed = Lists.newArrayList();
List<String> lists = Files.readAllLines(Paths.get("/xym/sync/DATA0"));
lists.stream().forEach(
line -> {
String[] split = line.split("\\001");
long x = Bytes.toLong(split[split.length - 1].getBytes());
split[split.length-1]= x +"";
processed.add(String.join("\001",split));
}
);
Files.write(Paths.get("/xym/sync/DATA2"),processed);
}
public static byte[] hex2Bytes1(String src){
byte[] res = new byte[src.length()/2];
char[] chs = src.toCharArray();
int[] b = new int[2];
for(int i=0,c=0; i<chs.length; i+=2,c++){
for(int j=0; j<2; j++){
if(chs[i+j]>='0' && chs[i+j]<='9'){
b[j] = (chs[i+j]-'0');
}else if(chs[i+j]>='A' && chs[i+j]<='F'){
b[j] = (chs[i+j]-'A'+10);
}else if(chs[i+j]>='a' && chs[i+j]<='f'){
b[j] = (chs[i+j]-'a'+10);
}
}
b[0] = (b[0]&0x0f)<<4;
b[1] = (b[1]&0x0f);
res[c] = (byte) (b[0] | b[1]);
}
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment