package routingtile;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.HashMap;
import com.sun.org.apache.bcel.internal.generic.NEW;
public class TestMain {
private static RoutingTileHeader header = new RoutingTileHeader();
private static SimpleIntersectionList simpleIntersection = new SimpleIntersectionList();
private static LinkList link = new LinkList();
private static RoutingIdRangeList routingIdRange = new RoutingIdRangeList();
protected static final int BITS_PER_BYTE = 0x8;
private static Readblom rb;
//创建一个指针
private static int pointer;
// //如何判断一个Int型值,它的第nbit位是否是1还是0
// private static boolean isIntNumberNBitONEInBinary(int number,int nbit){
// boolean result = false;
// if((number%(Math.pow(2, nbit)))/(Math.pow(2, nbit-1)) >= 1.0){
// result = true;
// }
// return result;
// }
public static void main(String[] agrs)throws Exception{
//header赋值
routingTileHeader();
//调用交叉点方法
simpleIntersection();
//调用link方法
link();
//调用routingIdRange方法
routingIdRange();
}
/**
* routingIdRange方法,返回RoutingIdRangeList
* @throws IOException
*/
public static RoutingIdRangeList routingIdRange() throws IOException{
//获取二进制文件
StringBuilder strB = HexFinder.readData();
//创建一个mp用于接收返回值
HashMap<String, Integer> mp;
//初始化LinkIdRangeListOffset指针位置
HexFinder.initialize(header.getLinkIdRangeListOffset());
//numFeatureRanges
RoutingIdRangeList rIRL = new RoutingIdRangeList();
NumRoutingListElements nRLE = new NumRoutingListElements();
mp = HexFinder.dicedall(16,pointer, strB);
pointer = mp.get("pointer");
int numFeatureRanges = mp.get("value");
rIRL.setNumFeatureRanges(nRLE);
nRLE.setNumFeatureRanges(numFeatureRanges);
System.out.println("numFeatureRanges:" + nRLE.getNumFeatureRanges() + "\r\n");
ArrayList<RouteNumberRange> featureranges = new ArrayList<RouteNumberRange>();
for (int m = 0; m < nRLE.getNumFeatureRanges(); m++) {
RouteNumberRange rNr = new RouteNumberRange();
mp = HexFinder.dicedall(16,pointer, strB);
pointer = mp.get("pointer");
int startFeatureId = mp.get("value");
rNr.setStartFeatureId(nRLE);
nRLE.setStartFeatureId(startFeatureId);
System.out.println("startFeatureId:" + nRLE.getStartFeatureId());
mp = HexFinder.dicedall(16,pointer, strB);
pointer = mp.get("pointer");
int endFeatureId = mp.get("value");
rNr.setEndFeatureId(nRLE);
nRLE.setEndFeatureId(endFeatureId);
System.out.println("ENDFeatureId:" + nRLE.getEndFeatureId());
}
return routingIdRange;
}
/**
* link方法,返回LinkList
* @throws IOException
*/
public static LinkList link() throws IOException{
//获取二进制文件
StringBuilder strB = HexFinder.readData();
//创建一个mp用于接收返回值
HashMap<String, Integer> mp;
//初始化LinksOffset指针位置
HexFinder.initialize(header.getLinksOffset());
//numLinks
LinkList linkList = new LinkList();
mp = HexFinder.dicedall(16,pointer, strB);
pointer = mp.get("pointer");
int numnumLinks = mp.get("value");
linkList.setNumnumLinks(numnumLinks);
System.out.println("numLinks:" + linkList.getNumnumLinks() + "\r\n");
ArrayList<Link> links = new ArrayList<Link>();
for (int j = 0; j < linkList.getNumnumLinks(); j++) {
//linkList.getNumnumLinks()
Link lk = new Link();
FeatureLength FL = new FeatureLength();
//先读8位,如果最高位是1舍弃掉1后要后面7位,,,再读8位,到最后一字节是最高位是0结束
for (int k = 0; k < 32/BITS_PER_BYTE; k++) {
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
int first = mp.get("value");
if (first == 1) {
mp = HexFinder.dicedall(7, pointer, strB);
pointer = mp.get("pointer");
int one = mp.get("value");
String strone = Integer.toBinaryString(one);
//一串二进制
}else {
mp = HexFinder.dicedall(7, pointer, strB);
pointer = mp.get("pointer");
int last = mp.get("value");
String strlast = Integer.toBinaryString(last);
//最后七位二进制
break;
}
//这几个二进制串在一起(<32)再转成十进制就是length的值
// String result = strone + strlast;
// int length = Integer.parseInt(strone + strlast);
// FL.setLength(length);
System.out.println(“length:” + FL.getLength());
}
AttributeSource aBS = new AttributeSource(); //选择 0 1
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
int attrSource = mp.get("value");
RoutingAttributeInfo rABI = new RoutingAttributeInfo(); //选择
//attrsource == 0 INDEXED = 0 输出INDEXED(0)
if (attrSource == 0) {
aBS.setINDEXED(attrSource);
System.out.println("INDEXED (" + aBS.getINDEXED() + ")");
FixedRoadAttributeSetListIndex fRASLI = new FixedRoadAttributeSetListIndex();
mp = HexFinder.dicedall(8,pointer, strB);
pointer = mp.get("pointer");
int fixedroadattributesetlistindex = mp.get("value");
fRASLI.setFixedRoadAttributeSetListIndex(fixedroadattributesetlistindex);
System.out.println("fixedRoadAttributeSetListIndex:" + fRASLI.getFixedRoadAttributeSetListIndex());
lk.setLength(FL);
}else {
aBS.setEXPLICIT(attrSource);
System.out.println("EXPLICIT (" + aBS.getEXPLICIT() + ")");
SharedRoadAttributes sRA = new SharedRoadAttributes();
RoutingRoadAttributes rRA = new RoutingRoadAttributes();
PriorityRoadClass pRC = new PriorityRoadClass();
LinkType lT = new LinkType();
Direction d = new Direction();
FunctionalRoadClass fRC = new FunctionalRoadClass();
//SharedRoadAttributes
mp = HexFinder.dicedall(4,pointer, strB);
pointer = mp.get("pointer");
int priorityroadclass = mp.get("value");
pRC.setPriorityRoadClass(priorityroadclass);
System.out.println("priorityRoadClass:" + pRC.getPriorityRoadClass());
mp = HexFinder.dicedall(4,pointer, strB); //14个选择
pointer = mp.get("pointer");
int linkType = mp.get("value");
lT.setLinkType(linkType);
switch (linkType) {
case 0:
System.out.println("linkType: " + "NO_SPECIAL (" + lT.getLinkType() + ")");
break;
case 1:
System.out.println("linkType: " + "RAMP (" + lT.getLinkType() + ")");
break;
case 2:
System.out.println("linkType: " + "ROUNDABOUT (" + lT.getLinkType() + ")");
break;
case 3:
System.out.println("linkType: " + "PARALLEL (" + lT.getLinkType() + ")");
break;
case 4:
System.out.println("linkType: " + "SERVICE_ROAD (" + lT.getLinkType() + ")");
break;
case 5:
System.out.println("linkType: " + "MAIN_ROAD (" + lT.getLinkType() + ")");
break;
case 6:
System.out.println("linkType: " + "SQUARE (" + lT.getLinkType() + ")");
break;
case 8:
System.out.println("linkType: " + "PEDESTRIAN_ZONE (" + lT.getLinkType() + ")");
break;
case 9:
System.out.println("linkType: " + "PEDESTRIAN (" + lT.getLinkType() + ")");
break;
case 10:
System.out.println("linkType: " + "ROUNDABOUT_INTERIOR (" + lT.getLinkType() + ")");
break;
case 11:
System.out.println("linkType: " + "SLIP_ROAD (" + lT.getLinkType() + ")");
break;
case 12:
System.out.println("linkType: " + "SPECIAL_TRAFFIC_FIGURE (" + lT.getLinkType() + ")");
break;
case 13:
System.out.println("linkType: " + "BOUNDARY (" + lT.getLinkType() + ")");
break;
default:
break;
}
mp = HexFinder.dicedall(2,pointer, strB); //4个选择
pointer = mp.get("pointer");
int travelDirection = mp.get("value");
d.setTravelDirection(travelDirection);
switch (travelDirection) {
case 0:
System.out.println("travelDirection: " + "IN_NO_DIRECTION (" + d.getTravelDirection() + ")");
break;
case 1:
System.out.println("travelDirection: " + "IN_POSITIVE_DIRECTION (" + d.getTravelDirection() + ")");
break;
case 2:
System.out.println("travelDirection: " + "IN_NEGATIVE_DIRECTION (" + d.getTravelDirection() + ")");
break;
case 3:
System.out.println("travelDirection: " + "IN_BOTH_DIRECTIONS (" + d.getTravelDirection() + ")");
break;
default:
break;
}
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
boolean ferry;
if(mp.get("value") == 1){
ferry = true;
}else{
ferry = false;
}
sRA.setFerry(ferry);
System.out.println("ferry:" + sRA.getFerry());
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
boolean tunnel;
if(mp.get("value") == 1){
tunnel = true;
}else{
tunnel = false;
}
sRA.setTunnel(tunnel);
System.out.println("tunnel:" + sRA.getTunnel());
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
boolean bridge;
if(mp.get("value") == 1){
bridge = true;
}else{
bridge = false;
}
sRA.setBridge(bridge);
System.out.println("bridge:" + sRA.getBridge());
mp = HexFinder.dicedall(2,pointer, strB); //4个选择
pointer = mp.get("pointer");
int toll = mp.get("value");
d.setToll(toll);
switch (toll) {
case 0:
System.out.println("toll: " + "IN_NO_DIRECTION (" + d.getToll() + ")");
break;
case 1:
System.out.println("toll: " + "IN_POSITIVE_DIRECTION (" + d.getToll() + ")");
break;
case 2:
System.out.println("toll: " + "IN_NEGATIVE_DIRECTION (" + d.getToll() + ")");
break;
case 3:
System.out.println("toll: " + "IN_BOTH_DIRECTIONS (" + d.getToll() + ")");
break;
default:
break;
}
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
boolean controlledAccess;
if(mp.get("value") == 1){
controlledAccess = true;
}else{
controlledAccess = false;
}
sRA.setControlledAccess(controlledAccess);
System.out.println("controlledAccess:" + sRA.getControlledAccess());
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
boolean serviceArea;
if(mp.get("value") == 1){
serviceArea = true;
}else{
serviceArea = false;
}
sRA.setServiceArea(serviceArea);
System.out.println("serviceArea:" + sRA.getServiceArea());
//RoutingRoadAttributes
mp = HexFinder.dicedall(3,pointer, strB);
pointer = mp.get("pointer");
int functionalRoadClass = mp.get("value");
fRC.setFunctionalRoadClass(functionalRoadClass);
System.out.println("functionalRoadClass:" + fRC.getFunctionalRoadClass());
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
boolean urban;
if(mp.get("value") == 1){
urban = true;
}else{
urban = false;
}
rRA.setUrban(urban);
System.out.println("urban:" + rRA.getUrban());
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
boolean complexIntersection;
if(mp.get("value") == 1){
complexIntersection = true;
}else{
complexIntersection = false;
}
rRA.setComplexIntersection(complexIntersection);
System.out.println("complexIntersection:" + rRA.getComplexIntersection());
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
boolean pluralJunction;
if(mp.get("value") == 1){
pluralJunction = true;
}else{
pluralJunction = false;
}
rRA.setPluralJunction(pluralJunction);
System.out.println("pluralJunction:" + rRA.getPluralJunction());
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
boolean motorway;
if(mp.get("value") == 1){
motorway = true;
}else{
motorway = false;
}
rRA.setMotorway(motorway);
System.out.println("motorway:" + rRA.getMotorway());
lk.setAttrSource(aBS);
lk.setAttrInfo(rABI);
sRA.setPriorityRoadClass(pRC);
sRA.setLinkType(lT);
sRA.setTravelDirection(d);
sRA.setFerry(ferry);
sRA.setTunnel(tunnel);
sRA.setBridge(bridge);
sRA.setToll(d);
sRA.setControlledAccess(controlledAccess);
sRA.setServiceArea(serviceArea);
rRA.setFunctionalRoadClass(fRC);
}
AverageSpeed aS = new AverageSpeed();
LinkSector lS = new LinkSector();
mp = HexFinder.dicedall(8,pointer, strB);
pointer = mp.get("pointer");
int averageSpeed = mp.get("value");
aS.setAverageSpeed(averageSpeed);
System.out.println("averageSpeed:" + aS.getAverageSpeed());
mp = HexFinder.dicedall(6,pointer, strB);
pointer = mp.get("pointer");
int startangle = mp.get("value");
lS.setStartAngle(startangle);
System.out.println("startAngle:" + lS.getStartAngle());
mp = HexFinder.dicedall(6,pointer, strB);
pointer = mp.get("pointer");
int endangle = mp.get("value");
lS.setEndAngle(endangle);
System.out.println("endAngle:" + lS.getEndAngle() + "\r\n");
lk.setAverageSpeed(aS);
lk.setStartAngle(lS);
lk.setEndAngle(lS);
links.add(lk);
}
return link;
}
/**
* simpleIntersection方法,返回SimpleIntersectionList
* @throws IOException
*/
public static SimpleIntersectionList simpleIntersection() throws IOException{
//获取二进制文件
StringBuilder strB = HexFinder.readData();
//创建一个mp用于接收返回值
HashMap<String, Integer> mp;
//初始化SimpleIntersectionOffset指针位置
HexFinder.initialize(header.getSimpleIntersectionOffset());
//numIntersections
SimpleIntersectionList numIntersectionList = new SimpleIntersectionList();
mp = HexFinder.dicedall(16,pointer, strB);
pointer = mp.get("pointer");
int numIntersection = mp.get("value");
numIntersectionList.setNumIntersections(numIntersection);
// System.out.println(numIntersectionList.getNumIntersections());
ArrayList<SimpleIntersection> simpleIntersections =new ArrayList<SimpleIntersection>();
for(int i = 0; i<simpleIntersection.getNumIntersections(); i++)
{
// 放到CoordXYOffset对象中
CoordXYOffset coordXYOffset = new CoordXYOffset();
SimpleIntersection sIntersection = new SimpleIntersection();
mp = HexFinder.dicedall(14,pointer, strB);
pointer = mp.get("pointer");
int dx = mp.get("value");
if (14 < 64 && (dx & (1L << (14-1))) != 0) {
dx |= (-1L << 14);
}
mp = HexFinder.dicedall(14,pointer, strB);
pointer = mp.get("pointer");
int dy = mp.get("value");
if (14 < 64 && (dy & (1L << (14-1))) != 0) {
dy |= (-1L << 14);
}
coordXYOffset.setDx(dx);
coordXYOffset.setDy(dy);
mp = HexFinder.dicedall(8,pointer, strB);
pointer = mp.get("pointer");
int numLinks = mp.get("value");
sIntersection.setNumLinks(numLinks);
sIntersection.setPosition(coordXYOffset);
ArrayList<IntOrExtDirectedLinkReference> connectedLinks = new ArrayList<IntOrExtDirectedLinkReference>();
for(int n = 0; n<sIntersection.getNumLinks(); n++)
{
DirectedLinkReference dLR= new DirectedLinkReference();
ExternalDirectedLinkReference eDLR = new ExternalDirectedLinkReference();
IntOrExtDirectedLinkReference iEDLR = new IntOrExtDirectedLinkReference();
LinkReferenceChoice choice = new LinkReferenceChoice();
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
int isExternalLinkReference = mp.get("value");
//IsExternalLinkReference等于false时
if(isExternalLinkReference==0){
iEDLR.setIsExternalLinkReference(false);
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
boolean positiveLinkDirection;
if(mp.get("value") == 1){
positiveLinkDirection = true;
}else{
positiveLinkDirection = false;
}
dLR.setPositiveLinkDirection(positiveLinkDirection);
mp = HexFinder.dicedall(15,pointer, strB);
pointer = mp.get("pointer");
int linkId = mp.get("value");
dLR.setLinkId(linkId);
choice.setInternalLinkReference(dLR);
choice.setExternalLinkReference(eDLR);
iEDLR.setLinkReferenceChoice(choice);
connectedLinks.add(iEDLR);
}else{ //true
iEDLR.setIsExternalLinkReference(true);
mp = HexFinder.dicedall(8,pointer, strB);
pointer = mp.get("pointer");
int extTileIdx = mp.get("value");
mp = HexFinder.dicedall(1,pointer, strB);
pointer = mp.get("pointer");
boolean positiveLinkDirection;
if(mp.get("value") == 1){
positiveLinkDirection = true;
}else{
positiveLinkDirection = false;
}
dLR.setPositiveLinkDirection(positiveLinkDirection);
mp = HexFinder.dicedall(15,pointer, strB);
pointer = mp.get("pointer");
int linkId = mp.get("value");
dLR.setLinkId(linkId);
eDLR.setTileExternalLinkReference(dLR);
eDLR.setExtTileIdx(extTileIdx);
eDLR.setTileExternalLinkReference(dLR);
choice.setInternalLinkReference(dLR);
choice.setExternalLinkReference(eDLR);
iEDLR.setLinkReferenceChoice(choice);
connectedLinks.add(iEDLR);
}
}
sIntersection.setConnectedLinks(connectedLinks);
simpleIntersections.add(sIntersection);
}
// simpleIntersection.setSimpleIntersection(simpleIntersections);
//输出所有值
/for (SimpleIntersection Intersection : simpleIntersections) {
System.out.println("\n"+“dx:” + Intersection.getPosition().getDx());
System.out.println(“dy:” + Intersection.getPosition().getDy());
System.out.println(“numLinks:” + Intersection.getNumLinks());
for (IntOrExtDirectedLinkReference Intorextdirectedlinkreference: Intersection.getConnectedLinks() ) {
System.out.println(“isExternalLinkReference:” + Intorextdirectedlinkreference.getIsExternalLinkReference());
if (Intorextdirectedlinkreference.getIsExternalLinkReference()) {
System.out.println(“extTileIdx:” + Intorextdirectedlinkreference.getLinkReferenceChoice().getExternalLinkReference().getExtTileIdx());
System.out.println(“positiveLinkDirection:” + Intorextdirectedlinkreference.getLinkReferenceChoice().getExternalLinkReference().getTileExternalLinkReference().getPositiveLinkDirection());
System.out.println(“LinkId:” + Intorextdirectedlinkreference.getLinkReferenceChoice().getExternalLinkReference().getTileExternalLinkReference().getLinkId());
}else {
System.out.println(“positiveLinkDirection:” + Intorextdirectedlinkreference.getLinkReferenceChoice().getInternalLinkReference().getPositiveLinkDirection());
System.out.println(“LinkId:” + Intorextdirectedlinkreference.getLinkReferenceChoice().getInternalLinkReference().getLinkId());
}
}
}/
//取第几条
/* SimpleIntersection intersection = simpleIntersection.getSimpleIntersection().get(15);
System.out.println(“dx:” + intersection.getPosition().getDx());
System.out.println(“dy:” + intersection.getPosition().getDy());
System.out.println(“NumLinks:” + intersection.getNumLinks());
ArrayList connectedLinks = intersection.getConnectedLinks();
for (int i = 0; i < connectedLinks.size(); i++) {
if (connectedLinks.get(i).getIsExternalLinkReference()) {
System.out.println(“IsExternalLinkReference:” + connectedLinks.get(i).getIsExternalLinkReference());
System.out.println(“extTileIdx:” + connectedLinks.get(i).getLinkReferenceChoice().getExternalLinkReference().getExtTileIdx());
System.out.println(“positiveLinkDirection:” + connectedLinks.get(i).getLinkReferenceChoice().getExternalLinkReference().getTileExternalLinkReference().getPositiveLinkDirection());
System.out.println(“LinkId:” + connectedLinks.get(i).getLinkReferenceChoice().getExternalLinkReference().getTileExternalLinkReference().getLinkId());
}else {
System.out.println(“IsExternalLinkReference:” + connectedLinks.get(i).getIsExternalLinkReference());
System.out.println(“positiveLinkDirection:” + connectedLinks.get(i).getLinkReferenceChoice().getInternalLinkReference().getPositiveLinkDirection());
System.out.println(“LinkId:” + connectedLinks.get(i).getLinkReferenceChoice().getInternalLinkReference().getLinkId());
}
}
/
return simpleIntersection;
}
/*
* routingTileHeader方法,给header赋值
* @throws IOException
/
public static void routingTileHeader() throws IOException{
RandomAccessFile in=new RandomAccessFile(“first.dat”,“r”);
rb = new Readblom(2);
in.read(rb.buffer, 0, 2);
RoutingContentMask routingcontentmask = new RoutingContentMask();
routingcontentmask.setHasFixedRoadAttributeSetList(rb.readBool());
routingcontentmask.setHasSimpleIntersectionList(rb.readBool());
routingcontentmask.setHasLinkList(rb.readBool());
routingcontentmask.setHasRouteUpLinkList(rb.readBool());
routingcontentmask.setHasRouteDownLinkList(rb.readBool());
routingcontentmask.setHasLinkToTileList(rb.readBool());
routingcontentmask.setHasLinkIdRangeList(rb.readBool());
routingcontentmask.setHasSimpleIntersectionIdRangeList(rb.readBool());
routingcontentmask.setHasAttributeMaps(rb.readBool());
routingcontentmask.setHasExternalTileIdList(rb.readBool());
header.setContentMask(routingcontentmask);
if(header.getContentMask().getHasFixedRoadAttributeSetList() == true)
{
header.setFixedRoadAttributeSetListOffset(in.readInt());
}
if(header.getContentMask().getHasSimpleIntersectionList() == true)
{
header.setSimpleIntersectionOffset(in.readInt());
}
if(header.getContentMask().getHasLinkList()== true)
{
header.setLinksOffset(in.readInt());
}
if(header.getContentMask().getHasRouteUpLinkList()== true)
{
header.setRouteUpLinksOffset(in.readInt());
}
if(header.getContentMask().getHasRouteDownLinkList()== true)
{
header.setRouteDownLinksOffset(in.readInt());
}
if(header.getContentMask().getHasLinkToTileList()== true)
{
header.setLink2TileListOffset(in.readInt());
}
if(header.getContentMask().getHasLinkIdRangeList()== true)
{
header.setLinkIdRangeListOffset(in.readInt());
}
if(header.getContentMask().getHasSimpleIntersectionIdRangeList()== true)
{
header.setSimplIntIdRangeListOffset(in.readInt());
}
if(header.getContentMask().getHasAttributeMaps()== true)
{
header.setAttributeMapsOffset(in.readInt());
}
if(header.getContentMask().getHasExternalTileIdList()== true)
{
header.setExternalTileIdListOffset(in.readInt());
}
/ System.out.println(
+header.getFixedRoadAttributeSetListOffset() + “\r\n”
+header.getSimpleIntersectionOffset() + “\r\n”
+header.getLinksOffset() + “\r\n”
+header.getRouteUpLinksOffset() + “\r\n”
+header.getRouteDownLinksOffset() + “\r\n”
+header.getLink2TileListOffset() + “\r\n”
+header.getSimplIntIdRangeListOffset() + “\r\n”
+header.getLinkIdRangeListOffset() + “\r\n”
+header.getAttributeMapsOffset() + “\r\n”
+header.getExternalTileIdListOffset() + “\r\n”);
*/
in.seek(header.getSimpleIntersectionOffset());
simpleIntersection.setNumIntersections(in.readShort());
}
}
class Readblom{
protected int bytePosition;
protected int bitOffset;
protected static final byte BYTE_MOD_MASK = 0x7;
protected static final int BITS_PER_BYTE = 0x8;
protected static final int BITS_PER_LONG = 0x40;
public byte[] buffer;
Readblom(int b)
{
buffer = new byte[b];
}
public long getBitPosition()
{
return BITS_PER_BYTE * bytePosition + bitOffset;
}
//设置bit位置
public void setBitPosition(final long bitPosition) throws IOException
{
bitOffset = (int)(bitPosition % 8);
bytePosition = (int)(bitPosition / BITS_PER_BYTE);
}
private byte nextByte() throws IOException
{
if (bytePosition >= buffer.length)
throw new IOException("ByteArrayBitStreamReader: Unable to read byte on offset position " +
(bytePosition + 1) + ". It’s beyond end of the stream with length " + buffer.length + “.”);
return buffer[bytePosition++];
}
/**
* Returns the next unsigned byte without resetting the bit offset.
*
* @return Read next byte.
*
* @throws IOException If the reading failed.
/
private int nextUnsignedByte() throws IOException
{
return nextByte() & 0xff;
}
public boolean readBool() throws IOException
{
return readBits(1) == 1;
}
//有符号位
public long readSignedBits(final int numBits) throws IOException
{
long result = readBits(numBits);
/
* Perform a sign extension if needed.
* 1L << 64 in Java is not 0L, but 1L, so treat numBits == 64 as a special case
* (numBits == 64 does not need sign extension anyway)
/
if (numBits < 64 && (result & (1L << (numBits - 1))) != 0)
{
result |= (-1L << numBits);
}
return result;
}
public long readBits(final int numBits) throws IOException
{
int bitsToRead = bitOffset + numBits;
final int nextBitOffset = bitsToRead & BYTE_MOD_MASK;
long accum = 0L;
while (bitsToRead > 0)
{
accum = (accum << BITS_PER_BYTE) | nextUnsignedByte();
bitsToRead -= BITS_PER_BYTE;
}
bitOffset = nextBitOffset;
if (nextBitOffset != 0)
{
bytePosition–;
}
/
* Shift away unwanted bits on the right and mask out unwanted bits on
* the left.
*/
return (accum >>> -bitsToRead) & (-1L >>> (BITS_PER_LONG - numBits));
}
}
class RoutingContentMask{
private boolean hasFixedRoadAttributeSetList;
private boolean hasSimpleIntersectionList;
private boolean hasLinkList;
private boolean hasRouteUpLinkList;
private boolean hasRouteDownLinkList;
private boolean hasLinkToTileList;
private boolean hasLinkIdRangeList;
private boolean hasSimpleIntersectionIdRangeList;
private boolean hasAttributeMaps;
private boolean hasExternalTileIdList;
public RoutingContentMask() {}
public void setHasFixedRoadAttributeSetList(boolean hasFixedRoadAttributeSetList) {
this.hasFixedRoadAttributeSetList = hasFixedRoadAttributeSetList;
}
public boolean getHasFixedRoadAttributeSetList() {
return hasFixedRoadAttributeSetList;
}
public void setHasSimpleIntersectionList(boolean hasSimpleIntersectionList) {
this.hasSimpleIntersectionList = hasSimpleIntersectionList;
}
public boolean getHasSimpleIntersectionList() {
return hasSimpleIntersectionList;
}
public void setHasLinkList(boolean hasLinkList) {
this.hasLinkList = hasLinkList;
}
public boolean getHasLinkList() {
return hasLinkList;
}
public void setHasRouteUpLinkList(boolean hasRouteUpLinkList) {
this.hasRouteUpLinkList = hasRouteUpLinkList;
}
public boolean getHasRouteUpLinkList() {
return hasRouteUpLinkList;
}
public void setHasRouteDownLinkList(boolean hasRouteDownLinkList) {
this.hasRouteDownLinkList = hasRouteDownLinkList;
}
public boolean getHasRouteDownLinkList() {
return hasRouteDownLinkList;
}
public void setHasLinkToTileList(boolean hasLinkToTileList) {
this.hasLinkToTileList = hasLinkToTileList;
}
public boolean getHasLinkToTileList() {
return hasLinkToTileList;
}
public void setHasLinkIdRangeList(boolean hasLinkIdRangeList) {
this.hasLinkIdRangeList = hasLinkIdRangeList;
}
public boolean getHasLinkIdRangeList() {
return hasLinkIdRangeList;
}
public void setHasSimpleIntersectionIdRangeList(boolean hasSimpleIntersectionIdRangeList) {
this.hasSimpleIntersectionIdRangeList = hasSimpleIntersectionIdRangeList;
}
public boolean getHasSimpleIntersectionIdRangeList() {
return hasSimpleIntersectionIdRangeList;
}
public void setHasAttributeMaps(boolean hasAttributeMaps) {
this.hasAttributeMaps = hasAttributeMaps;
}
public boolean getHasAttributeMaps() {
return hasAttributeMaps;
}
public void setHasExternalTileIdList(boolean hasExternalTileIdList) {
this.hasExternalTileIdList = hasExternalTileIdList;
}
public boolean getHasExternalTileIdList() {
return hasExternalTileIdList;
}
}
class RoutingTileHeader {
RoutingContentMask contentMask;
int fixedRoadAttributeSetListOffset;
int simpleIntersectionOffset;
int linksOffset;
int routeUpLinksOffset;
int routeDownLinksOffset;
int link2TileListOffset;
int linkIdRangeListOffset;
int simplIntIdRangeListOffset;
int attributeMapsOffset;
int externalTileIdListOffset;
public RoutingTileHeader() {}
public RoutingContentMask getContentMask() {
return contentMask;
}
public void setContentMask(RoutingContentMask contentMask) {
this.contentMask = contentMask;
}
public int getFixedRoadAttributeSetListOffset() {
return fixedRoadAttributeSetListOffset;
}
public void setFixedRoadAttributeSetListOffset(int fixedRoadAttributeSetListOffset) {
this.fixedRoadAttributeSetListOffset = fixedRoadAttributeSetListOffset;
}
public int getSimpleIntersectionOffset() {
return simpleIntersectionOffset;
}
public void setSimpleIntersectionOffset(int simpleIntersectionOffset) {
this.simpleIntersectionOffset = simpleIntersectionOffset;
}
public int getLinksOffset() {
return linksOffset;
}
public void setLinksOffset(int linksOffset) {
this.linksOffset = linksOffset;
}
public int getRouteUpLinksOffset() {
return routeUpLinksOffset;
}
public void setRouteUpLinksOffset(int routeUpLinksOffset) {
this.routeUpLinksOffset = routeUpLinksOffset;
}
public int getRouteDownLinksOffset() {
return routeDownLinksOffset;
}
public void setRouteDownLinksOffset(int routeDownLinksOffset) {
this.routeDownLinksOffset = routeDownLinksOffset;
}
public int getLink2TileListOffset() {
return link2TileListOffset;
}
public void setLink2TileListOffset(int link2TileListOffset) {
this.link2TileListOffset = link2TileListOffset;
}
public int getLinkIdRangeListOffset() {
return linkIdRangeListOffset;
}
public void setLinkIdRangeListOffset(int linkIdRangeListOffset) {
this.linkIdRangeListOffset = linkIdRangeListOffset;
}
public int getSimplIntIdRangeListOffset() {
return simplIntIdRangeListOffset;
}
public void setSimplIntIdRangeListOffset(int simplIntIdRangeListOffset) {
this.simplIntIdRangeListOffset = simplIntIdRangeListOffset;
}
public int getAttributeMapsOffset() {
return attributeMapsOffset;
}
public void setAttributeMapsOffset(int attributeMapsOffset) {
this.attributeMapsOffset = attributeMapsOffset;
}
public int getExternalTileIdListOffset() {
return externalTileIdListOffset;
}
public void setExternalTileIdListOffset(int externalTileIdListOffset) {
this.externalTileIdListOffset = externalTileIdListOffset;
}
}
class SimpleIntersectionList {
private int numIntersections;
private ArrayList simpleIntersection;//simpleIntersection[numIntersections]
public SimpleIntersectionList() {}
public int getNumIntersections() {
return numIntersections;
}
public void setNumIntersections(int numIntersections) {
this.numIntersections = numIntersections;
}
public ArrayList getSimpleIntersection() {
return simpleIntersection;
}
public void setSimpleIntersection(ArrayList simpleIntersection) {
this.simpleIntersection = simpleIntersection; //simpleIntersection.addAll(simpleIntersection);
}
}
class SimpleIntersection{
private CoordXYOffset position;
private int numLinks;
private ExternalDirectedLinkReference externalLinkReference;
private ArrayList connectedLinks;//connectedLinks[numLinks]
public SimpleIntersection() {}
public CoordXYOffset getPosition() {
return position;
}
public void setPosition(CoordXYOffset position) {
this.position = position;
}
public int getNumLinks() {
return numLinks;
}
public void setNumLinks(int numLinks) {
this.numLinks = numLinks;
}
public ArrayList getConnectedLinks() {
return connectedLinks;
}
public void setConnectedLinks(ArrayList connectedLinks) {
this.connectedLinks = connectedLinks; //connectedLinks.addAll(connectedLinks);
}
public ExternalDirectedLinkReference getExternalLinkReference() {
return externalLinkReference;
}
public void setExternalLinkReference(
ExternalDirectedLinkReference externalLinkReference) {
this.externalLinkReference = externalLinkReference;
}
}
class CoordXYOffset{
private int numBits;
private int dx;
private int dy;
public CoordXYOffset() {}
public int getNumBits() {
return numBits;
}
public void setNumBits(int numBits) {
this.numBits = numBits;
}
public int getDx() {
return dx;
}
public void setDx(int dx) {
this.dx = dx;
}
public int getDy() {
return dy;
}
public void setDy(int dy) {
this.dy = dy;
}
}
class IntOrExtDirectedLinkReference{
private boolean isExternalLinkReference;
private LinkReferenceChoice linkReferenceChoice;
public IntOrExtDirectedLinkReference() {}
public boolean getIsExternalLinkReference() {
return isExternalLinkReference;
}
public void setIsExternalLinkReference(boolean isExternalLinkReference) {
this.isExternalLinkReference = isExternalLinkReference;
}
public LinkReferenceChoice getLinkReferenceChoice() {
return linkReferenceChoice;
}
public void setLinkReferenceChoice(LinkReferenceChoice linkReferenceChoice) {
this.linkReferenceChoice = linkReferenceChoice;
}
}
class LinkReferenceChoice{
private DirectedLinkReference internalLinkReference;
private ExternalDirectedLinkReference externalLinkReference;
public LinkReferenceChoice() {}
public DirectedLinkReference getInternalLinkReference() {
return internalLinkReference;
}
public void setInternalLinkReference(DirectedLinkReference internalLinkReference) {
this.internalLinkReference = internalLinkReference;
}
public ExternalDirectedLinkReference getExternalLinkReference() {
return externalLinkReference;
}
public void setExternalLinkReference(ExternalDirectedLinkReference externalLinkReference) {
this.externalLinkReference = externalLinkReference;
}
}
class DirectedLinkReference{
private boolean positiveLinkDirection;
private int linkId;
public DirectedLinkReference() {}
public boolean getPositiveLinkDirection() {
return positiveLinkDirection;
}
public void setPositiveLinkDirection(boolean positiveLinkDirection) {
this.positiveLinkDirection = positiveLinkDirection;
}
public int getLinkId() {
return linkId;
}
public void setLinkId(int linkId2) {
this.linkId = linkId2;
}
}
class LinkId{
private byte linkId;
public LinkId() {}
public byte getLinkId() {
return linkId;
}
public void setLinkId(byte linkId) {
this.linkId = linkId;
}
}
class ExternalDirectedLinkReference{
private int extTileIdx;
private DirectedLinkReference tileExternalLinkReference;
public ExternalDirectedLinkReference() {}
public int getExtTileIdx() {
return extTileIdx;
}
public void setExtTileIdx(int extTileIdx2) {
this.extTileIdx = extTileIdx2;
}
public DirectedLinkReference getTileExternalLinkReference() {
return tileExternalLinkReference;
}
public void setTileExternalLinkReference(DirectedLinkReference tileExternalLinkReference) {
this.tileExternalLinkReference = tileExternalLinkReference;
}
}
class SizeOfExternalTileIdList{
private int SizeOfExternalTileIdList;
public SizeOfExternalTileIdList() {}
public int getSizeOfExternalTileIdList() {
return SizeOfExternalTileIdList;
}
public void setSizeOfExternalTileIdList(int SizeOfExternalTileIdList) {
this.SizeOfExternalTileIdList = SizeOfExternalTileIdList;
}
}
class LinkList{
private int numnumLinks; //uint16 16位
private ArrayList link1; //有问题 //集合
public LinkList() {}
public int getNumnumLinks() {
return numnumLinks;
}
public void setNumnumLinks(int numnumLinks) {
this.numnumLinks = numnumLinks;
}
public ArrayList getLink1() {
return link1;
}
public void setLink1(ArrayList link1) {
this.link1 = link1;
}
}
class Link{
private FeatureLength length;
private AttributeSource attrSource;
private RoutingAttributeInfo attrInfo;
private AverageSpeed averageSpeed;
private LinkSector startAngle;
private LinkSector endAngle;
public Link() {}
public FeatureLength getLength() {
return length;
}
public void setLength(FeatureLength length) {
this.length = length;
}
public AttributeSource getAttrSource() {
return attrSource;
}
public void setAttrSource(AttributeSource attrSource) {
this.attrSource = attrSource;
}
public RoutingAttributeInfo getAttrInfo() {
return attrInfo;
}
public void setAttrInfo(RoutingAttributeInfo attrInfo) {
this.attrInfo = attrInfo;
}
public AverageSpeed getAverageSpeed() {
return averageSpeed;
}
public void setAverageSpeed(AverageSpeed averageSpeed) {
this.averageSpeed = averageSpeed;
}
public LinkSector getStartAngle() {
return startAngle;
}
public void setStartAngle(LinkSector startAngle) {
this.startAngle = startAngle;
}
public LinkSector getEndAngle() {
return endAngle;
}
public void setEndAngle(LinkSector endAngle) {
this.endAngle = endAngle;
}
}
class FeatureLength{
private int length; //varuint32 24位可变
public FeatureLength() {}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
}
class AttributeSource{
private int INDEXED; //1bit INDEXED = 0
private int EXPLICIT; //1bit EXPLICIT = 1
public AttributeSource() {}
public int getINDEXED() {
return INDEXED;
}
public void setINDEXED(int INDEXED) {
this.INDEXED = INDEXED;
}
public int getEXPLICIT() {
return EXPLICIT;
}
public void setEXPLICIT(int EXPLICIT) {
this.EXPLICIT = EXPLICIT;
}
}
class RoutingAttributeInfo{
private FixedRoadAttributeSetListIndex fixedRoadAttributeSetListIndex;
private FixedRoadAttributeSet fixedAttributes;
public RoutingAttributeInfo() {}
public FixedRoadAttributeSetListIndex getFixedRoadAttributeSetListIndex() {
return fixedRoadAttributeSetListIndex;
}
public void setFixedRoadAttributeSetListIndex(FixedRoadAttributeSetListIndex fixedRoadAttributeSetListIndex) {
this.fixedRoadAttributeSetListIndex = fixedRoadAttributeSetListIndex;
}
public FixedRoadAttributeSet getFixedAttributes() {
return fixedAttributes;
}
public void setFixedAttributes(FixedRoadAttributeSet fixedAttributes) {
this.fixedAttributes = fixedAttributes;
}
}
class FixedRoadAttributeSetListIndex{ //1bit INDEXED = 0时
private int fixedRoadAttributeSetListIndex; //varuint16 8位
public FixedRoadAttributeSetListIndex() {}
public int getFixedRoadAttributeSetListIndex() {
return fixedRoadAttributeSetListIndex;
}
public void setFixedRoadAttributeSetListIndex(int fixedRoadAttributeSetListIndex) {
this.fixedRoadAttributeSetListIndex = fixedRoadAttributeSetListIndex;
}
}
class FixedRoadAttributeSet{ //1bit EXPLICIT = 1时
private SharedRoadAttributes sharedAttr;
private RoutingRoadAttributes routingAttr;
public FixedRoadAttributeSet() {}
public SharedRoadAttributes getSharedAttr() {
return sharedAttr;
}
public void setSharedAttr(SharedRoadAttributes sharedAttr) {
this.sharedAttr = sharedAttr;
}
public RoutingRoadAttributes getRoutingAttr() {
return routingAttr;
}
public void setRoutingAttr(RoutingRoadAttributes routingAttr) {
this.routingAttr = routingAttr;
}
}
class SharedRoadAttributes{
private PriorityRoadClass priorityRoadClass;
private LinkType linkType;
private Direction travelDirection;
private boolean ferry; //所有布尔:1bit
private boolean tunnel;
private boolean bridge;
private Direction toll;
private boolean controlledAccess;
private boolean serviceArea;
public SharedRoadAttributes() {}
public PriorityRoadClass getPriorityRoadClass() {
return priorityRoadClass;
}
public void setPriorityRoadClass(PriorityRoadClass priorityRoadClass) {
this.priorityRoadClass = priorityRoadClass;
}
public LinkType getLinkType() {
return linkType;
}
public void setLinkType(LinkType linkType) {
this.linkType = linkType;
}
public Direction getTravelDirection() {
return travelDirection;
}
public void setTravelDirection(Direction travelDirection) {
this.travelDirection = travelDirection;
}
public boolean getFerry() {
return ferry;
}
public void setFerry(boolean ferry) {
this.ferry = ferry;
}
public boolean getTunnel() {
return tunnel;
}
public void setTunnel(boolean tunnel) {
this.tunnel = tunnel;
}
public boolean getBridge() {
return bridge;
}
public void setBridge(boolean bridge) {
this.bridge = bridge;
}
public Direction getToll() {
return toll;
}
public void setToll(Direction toll) {
this.toll = toll;
}
public boolean getControlledAccess() {
return controlledAccess;
}
public void setControlledAccess(boolean controlledAccess) {
this.controlledAccess = controlledAccess;
}
public boolean getServiceArea() {
return serviceArea;
}
public void setServiceArea(boolean serviceArea) {
this.serviceArea = serviceArea;
}
}
class PriorityRoadClass{
private int priorityRoadClass; //4bit
public PriorityRoadClass() {}
public int getPriorityRoadClass() {
return priorityRoadClass;
}
public void setPriorityRoadClass(int priorityroadclass) {
this.priorityRoadClass = priorityroadclass;
}
}
class LinkType{
private int linkType; //特殊:14中情况,0~D 4bit
public LinkType() {}
public int getLinkType() {
return linkType;
}
public void setLinkType(int linkType) {
this.linkType = linkType;
}
}
class Direction{ //特殊:四种情况:0~3 ,下面的两个不是都顺序输出的,两个东西
private int travelDirection; //2bit
private int toll; //2bit
public Direction() {}
public int getTravelDirection() {
return travelDirection;
}
public void setTravelDirection(int travelDirection) {
this.travelDirection = travelDirection;
}
public int getToll() {
return toll;
}
public void setToll(int toll) {
this.toll = toll;
}
}
class RoutingRoadAttributes {
private FunctionalRoadClass functionalRoadClass;
private boolean urban;
private boolean complexIntersection;
private boolean pluralJunction;
private boolean motorway;
public RoutingRoadAttributes() {}
public FunctionalRoadClass getFunctionalRoadClass() {
return functionalRoadClass;
}
public void setFunctionalRoadClass(FunctionalRoadClass functionalRoadClass) {
this.functionalRoadClass = functionalRoadClass;
}
public boolean getUrban() {
return urban;
}
public void setUrban(boolean urban) {
this.urban = urban;
}
public boolean getComplexIntersection() {
return complexIntersection;
}
public void setComplexIntersection(boolean complexIntersection) {
this.complexIntersection = complexIntersection;
}
public boolean getPluralJunction() {
return pluralJunction;
}
public void setPluralJunction(boolean pluralJunction) {
this.pluralJunction = pluralJunction;
}
public boolean getMotorway() {
return motorway;
}
public void setMotorway(boolean motorway) {
this.motorway = motorway;
}
}
class FunctionalRoadClass {
private int functionalRoadClass; //3bit
public FunctionalRoadClass() {}
public int getFunctionalRoadClass() {
return functionalRoadClass;
}
public void setFunctionalRoadClass(int functionalRoadClass) {
this.functionalRoadClass = functionalRoadClass;
}
}
class AverageSpeed{
private int averageSpeed; //uint8 8位
public AverageSpeed() {}
public int getAverageSpeed() {
return averageSpeed;
}
public void setAverageSpeed(int averageSpeed) {
this.averageSpeed = averageSpeed;
}
}
class LinkSector{ //下面的两个不是都顺序输出的,两个东西
private int startAngle; //6bit
private int endAngle; //6bit
public LinkSector() {}
public int getStartAngle() {
return startAngle;
}
public void setStartAngle(int startAngle) {
this.startAngle = startAngle;
}
public int getEndAngle() {
return endAngle;
}
public void setEndAngle(int endAngle) {
this.endAngle = endAngle;
}
}
class RoutingIdRangeList{
private NumRoutingListElements numFeatureRanges;
private ArrayList featureRange;
public RoutingIdRangeList() {}
public NumRoutingListElements getNumFeatureRanges() {
return numFeatureRanges;
}
public void setNumFeatureRanges(NumRoutingListElements numFeatureRanges) {
this.numFeatureRanges = numFeatureRanges;
}
public ArrayList getFeatureRange() {
return featureRange;
}
public void setFeatureRange(ArrayList featureRange) {
this.featureRange = featureRange;
}
}
class NumRoutingListElements{
private int numFeatureRanges;
private int startFeatureId;
private int endFeatureId;
public NumRoutingListElements() {}
public int getNumFeatureRanges() {
return numFeatureRanges;
}
public void setNumFeatureRanges(int numFeatureRanges) {
this.numFeatureRanges = numFeatureRanges;
}
public int getStartFeatureId() {
return startFeatureId;
}
public void setStartFeatureId(int startFeatureId) {
this.startFeatureId = startFeatureId;
}
public int getEndFeatureId() {
return endFeatureId;
}
public void setEndFeatureId(int endFeatureId) {
this.endFeatureId = endFeatureId;
}
}
class RouteNumberRange{
private NumRoutingListElements startFeatureId;
private NumRoutingListElements endFeatureId;
public RouteNumberRange() {}
public NumRoutingListElements getStartFeatureId() {
return startFeatureId;
}
public void setStartFeatureId(NumRoutingListElements startFeatureId) {
this.startFeatureId = startFeatureId;
}
public NumRoutingListElements getEndFeatureId() {
return endFeatureId;
}
public void setEndFeatureId(NumRoutingListElements endFeatureId) {
this.endFeatureId = endFeatureId;
}
}
package routingtile;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
public class HexFinder {
public static String format(byte[] bt) {
int line = 0;
StringBuilder buf = new StringBuilder();
for (byte d : bt) {
if (line % 16 == 0)
buf.append(String.format("%05x: ", line));
buf.append(String.format("%02x ", d));
line++;
if (line % 16 == 0)
buf.append("\n");
}
buf.append("\n");
return buf.toString();
}
public static byte[] readFile(String file) throws IOException {
InputStream is = new FileInputStream(file);
int length = is.available();
byte bt[] = new byte[length];
is.read(bt);
return bt;
}
/**
* 十六进制转二进制
*
* @param hexString
* @return
*/
public static String hexString2binaryString(String hexString) {
if (hexString == null || hexString.length() % 2 != 0)
return null;
String bString = "", tmp;
for (int i = 0; i < hexString.length(); i++) {
tmp = "0000"
+ Integer.toBinaryString(Integer.parseInt(
hexString.substring(i, i + 1), 16));
bString += tmp.substring(tmp.length() - 4);
}
return bString;
}
/**
* 读取十六进制文件后转成二进制
* @return strB
* @throws IOException
*/
public static StringBuilder readData() throws IOException{
//读取十六进制文件
byte[] bt = HexFinder.readFile("./first.dat");
String hexData = HexFinder.format(bt);
//按空格切割
String[] re = hexData.split("\n");
String sixData;
StringBuilder strB = new StringBuilder();
for (String string : re) {
String[] result = string.split("\\s+");
for (String s : result) {
if(s.length()>5){
continue;
}else{
//十六转二
sixData = hexString2binaryString(s);
strB.append(sixData);
}
}
}
return strB;
}
protected static final int BITS_BYTE = 8;
protected static int OFFSET = 0;
private static Boolean flag = true;
/**
* 将type数组按“:”切割,并截取strB中的位数
* @param type
* @param strB
* @return
* @throws IOException
*/
public static HashMap<String, Integer> dicedall(int offset,int pointer,StringBuilder strB) throws IOException{
HashMap<String, Integer> mp = new HashMap<String, Integer>();
String a;
int index;
//从736开始读取交叉点二进制中的数据
final int numbit = BITS_BYTE * OFFSET;
//第一次从736开始读
if(flag){
//模拟指针
index = numbit + offset;
a = strB.substring(numbit,index).trim();
flag = false;
}else{
//模拟指针
index = pointer + offset;
a = strB.substring(pointer,index).trim();
}
String lastValue = Long.valueOf(a,2).toString();
//放入mp中
mp.put("pointer", index);
mp.put("value", Integer.parseInt(lastValue));
// System.out.println(lastValue);
return mp;
}
/**
* 初始化指针位置
* @param type
* @param strB
* @return
* @return
* @throws IOException
*/
public static void initialize(int offsett){
OFFSET = offsett;
flag = true;
}
public static void write(String name,String hexString) throws IOException {
/**
* 创建一个可以往文件中写入字符数据的字符流输出流对象
* 创建时必须明确文件的目的地
* 如果文件不存在,这回自动创建。如果文件存在,则会覆盖。
* 当路径错误时会抛异常
*
* 当在创建时加入true参数,回实现对文件的续写。
*/
FileWriter fw = new FileWriter(".\\demo1.txt",true);
/**
* 调用该对象的write方法,向文件写入字符。
*
* 其实写入到了临时存储缓冲区中
*/
fw.write(name+":"+hexString+"\r\n");//windows中的换行为\r\n
/**
* 进行刷新,将字符写到目的地中。
*/
fw.flush();
/**
* 关闭流,关闭资源。在关闭前会调用flush方法 刷新缓冲区。关闭后在写的话,会抛IOException
*/
fw.close();
}
}