Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android SocketTimeoutException:读取超时_Java_Android_Xml Parsing_Inputstream - Fatal编程技术网

Java android SocketTimeoutException:读取超时

Java android SocketTimeoutException:读取超时,java,android,xml-parsing,inputstream,Java,Android,Xml Parsing,Inputstream,我有一个SocketTimeoutException:Read超时,我如何重新编写代码,使我没有这个SocketTimeoutException?我想读取所有字节[],当我没有要读取的数据时,我想退出一段时间并做其他事情,现在我看到我的应用程序等待超时,然后关闭一个套接字 In this line : while ((bytesRead = inputStream.read(content)) != -1) while((bytesRead=inputStream.read(cont

我有一个SocketTimeoutException:Read超时,我如何重新编写代码,使我没有这个SocketTimeoutException?我想读取所有字节[],当我没有要读取的数据时,我想退出一段时间并做其他事情,现在我看到我的应用程序等待超时,然后关闭一个套接字

In this line :  

 while ((bytesRead = inputStream.read(content)) != -1) 
while((bytesRead=inputStream.read(content))!=-1){
布尔all=false;
写入(内容,0,字节读取);
如果(bas.toByteArray()[bas.toByteArray().length-5]=(字节)'D'和&bas.toByteArray()[bas.toByteArray().length-6]=(字节)'O'){
int-inx=0;
ArrayList bytes1=新的ArrayList();
bytes1.clear();
for(字节数组:baos.toByteArray()){
如果(0==inx&&anArray==(字节)'F'){
bytes1.clear();
bytes1.add(错乱);
inx++;
}else如果(1==inx&&anArray==(字节)'A'){
bytes1.add(错乱);
inx++;
}else如果(2==inx&&anArray==(字节)'S'){
bytes1.add(错乱);
inx++;
}else如果(3==inx&&anArray==(字节“T”){
bytes1.add(错乱);
inx++;
}否则如果(inx<18){
bytes1.add(错乱);
inx++;
}否则{
如果(inx==18){
bytes1.add(错乱);
字节异或=(字节)(字节数1.get(0)^bytes1.get(1)^bytes1.get(2)^bytes1.get(3)^bytes1.get(4)^bytes1.get(5)^bytes1.get(6)^bytes1.get(7)
^获得(8)^bytes1.get(9)^bytes1.get(10)^bytes1.get(11)^bytes1.get(12)^bytes1.get(13)^bytes1.get(14)^bytes1.get(15)
^bytes1.get(16)^bytes1.get(17));
if(xor==anArray){
inx++;
}否则{
inx=0;
打破
}
}否则{
bytes1.add(错乱);
inx++;
字节[]大小=新字节[4];
大小[0]=bytes1.get(14);
size[1]=bytes1.get(15);
大小[2]=bytes1.get(16);
大小[3]=bytes1.get(17);
int dataSizeInt=解码(大小);
int totalSizeFrame=29+dataSizeInt;
if(bytes1.size()=TotalSizeName){
inx=0;
if(bytes1.get(totalSizeFrame-8)==(字节)“F”| | bytes1.get(totalSizeFrame-7)==(字节)“O”||
bytes1.get(totalSizeFrame-6)=(字节)“O”| | bytes1.get(totalSizeFrame-5)=(字节)“D”){
系统输出打印号(“Odebrano wszytsko od JUK-A”);
byte[]tablica=新字节[dataSizeInt];
对于(int i=19;i<19+dataSizeInt;i++){
tablica[i-19]=bytes1.get(i);
}
int crc16=crc16.crc16(tablica,dataSizeInt);
字节[]crcArray=新字节[4];
crcArray[0]=(字节)0;
crcArray[1]=(字节)0;
crcArray[2]=bytes1.get(bytes1.size()-10);
crcArray[3]=bytes1.get(bytes1.size()-9);
int crc=解码(crcArray);
System.out.println(“crc wyszlo”+crc16+“a u zioma”+crc);
InputStream isFromFirstData=新的ByteArrayInputStream(tablica);
if(字节1.get(13)=(字节)5){
试一试{
bytes1.clear();
inx=0;
rootXMl=Parser.parseroot1(isFromFirstData);
if(root==null){
System.out.println(“nie ma trasowki”);
}如果(!Objects.equals(root.getRm().get(0.getId(),rootXMl.getHalo().getRm_id())){
System.out.println(“Inna trasówka”);
}else if(ttt.ORDER_COUNT!=rootXMl.getHalo().getPgo_COUNT()){
System.out.println(“Inna liczba pgo”);
}else if(ttt.BIN\u COUNT!=rootXMl.getHalo().BIN\u COUNT){
System.out.println(“inna liczba bin”);
}
}捕获(XmlPullParserException | IOE异常){
e、 printStackTrace();
}
}else if(字节1.get(13)==(字节)11){
while ((bytesRead = inputStream.read(content)) != -1) {
                boolean all = false;
                baos.write(content, 0, bytesRead);

                if (baos.toByteArray()[baos.toByteArray().length - 5] == (byte) 'D' && baos.toByteArray()[baos.toByteArray().length - 6] == (byte) 'O') {
                    int inx = 0;
                    ArrayList<Byte> bytes1 = new ArrayList<>();
                    bytes1.clear();
                    for (Byte anArray : baos.toByteArray()) {
                        if (0 == inx && anArray == (byte) 'F') {
                            bytes1.clear();
                            bytes1.add(anArray);
                            inx++;
                        } else if (1 == inx && anArray == (byte) 'A') {
                            bytes1.add(anArray);
                            inx++;
                        } else if (2 == inx && anArray == (byte) 'S') {
                            bytes1.add(anArray);
                            inx++;
                        } else if (3 == inx && anArray == (byte) 'T') {
                            bytes1.add(anArray);
                            inx++;
                        } else if (inx < 18) {
                            bytes1.add(anArray);
                            inx++;
                        } else {
                            if (inx == 18) {
                                bytes1.add(anArray);
                                byte xor = (byte) (bytes1.get(0) ^ bytes1.get(1) ^ bytes1.get(2) ^ bytes1.get(3) ^ bytes1.get(4) ^ bytes1.get(5) ^ bytes1.get(6) ^ bytes1.get(7)
                                        ^ bytes1.get(8) ^ bytes1.get(9) ^ bytes1.get(10) ^ bytes1.get(11) ^ bytes1.get(12) ^ bytes1.get(13) ^ bytes1.get(14) ^ bytes1.get(15)
                                        ^ bytes1.get(16) ^ bytes1.get(17));
                                if (xor == anArray) {
                                    inx++;
                                } else {
                                    inx = 0;
                                    break;
                                }
                            } else {
                                bytes1.add(anArray);
                                inx++;
                                byte[] size = new byte[4];
                                size[0] = bytes1.get(14);
                                size[1] = bytes1.get(15);
                                size[2] = bytes1.get(16);
                                size[3] = bytes1.get(17);
                                int dataSizeInt = decode(size);

                                int totalSizeFrame = 29 + dataSizeInt;
                                if (bytes1.size() == totalSizeFrame) {
                                    inx = 0;
                                    if (bytes1.get(totalSizeFrame - 8) == (byte) 'F' || bytes1.get(totalSizeFrame - 7) == (byte) 'O' ||
                                            bytes1.get(totalSizeFrame - 6) == (byte) 'O' || bytes1.get(totalSizeFrame - 5) == (byte) 'D') {
                                        System.out.println("Odebrano wszytsko od JUK-A");

                                        byte[] tablica = new byte[dataSizeInt];

                                        for (int i = 19; i < 19 + dataSizeInt; i++) {
                                            tablica[i - 19] = bytes1.get(i);
                                        }

                                        int crc16 = Crc16.CRC16(tablica, dataSizeInt);

                                        byte[] crcArray = new byte[4];
                                        crcArray[0] = (byte) 0;
                                        crcArray[1] = (byte) 0;
                                        crcArray[2] = bytes1.get(bytes1.size() - 10);
                                        crcArray[3] = bytes1.get(bytes1.size() - 9);

                                        int crc = decode(crcArray);

                                        System.out.println("crc wyszlo " + crc16 + " a u zioma " + crc);

                                        InputStream isFromFirstData = new ByteArrayInputStream(tablica);
                                        if (bytes1.get(13) == (byte) 5) {
                                            try {
                                                bytes1.clear();
                                                inx = 0;
                                                rootXMl = Parser.parseToRoot1(isFromFirstData);
                                                if (root == null) {
                                                    System.out.println("nie ma trasowki");
                                                } else if (!Objects.equals(root.getRm().get(0).getId(), rootXMl.getHalo().getRm_id())) {
                                                    System.out.println("Inna trasówka");
                                                } else if (ttt.ORDER_COUNT != rootXMl.getHalo().getPgo_count()) {
                                                    System.out.println("Inna liczba pgo");
                                                } else if (ttt.BIN_COUNT != rootXMl.getHalo().bin_count) {
                                                    System.out.println("inna liczba bin");
                                                }
                                            } catch (XmlPullParserException | IOException e) {
                                                e.printStackTrace();
                                            }
                                        } else if (bytes1.get(13) == (byte) 11) {
                                            if (list.size() > 0)
                                                list.remove(0);
                                        }else if(bytes1.get(13) == (byte) 9 || bytes1.get(13) == (byte) 10){
                                            inx = 0;
                                            root2 = null;
                                            try {
                                                byte [] npw = new byte[4];
                                                npw[0] = bytes1.get(5);
                                                npw[1] = bytes1.get(6);
                                                npw[2] = bytes1.get(7);
                                                npw[3] = bytes1.get(8);


                                                root2 = Parser.parseToRoot2(isFromFirstData);
                                                System.out.println(root2.getHalo2().getBinId());
                                                outputStream.write(SendRequest.request((byte) 11,npw));
                                                outputStream.flush();
                                            } catch (XmlPullParserException e) {
                                                e.printStackTrace();
                                            }
                                        } else if (bytes1.get(13) == (byte) 6) {
                                            try {
                                                root = null;
                                                root = ttt.parseUpdate(isFromFirstData);
                                                long lEndTime = System.nanoTime();
                                                long output = lEndTime - lStartTime;

                                                System.out.println("Time to get trasowka: " + output / 1000000 / 1000);
                                                rowEntities = new ArrayList<>();
                                                rowEntities.clear();
                                                int id = 1;
                                                int rmId = 0;
                                                Random r = new Random();

                                                for (RM rm : root.getRm()) {
                                                    int orderId = 0;
                                                    for (ORDER order : rm.getArea().getOrder()) {
                                                        if (order.getAddress() != null) {
                                                            rowEntities.add(new RowEntity(id, rmId, orderId, order.getAddress(), true, false, r.nextDouble(), 1, "la", false, order.getLon(), order.getLat()));
                                                        } else if (order.getAdr() != null) {
                                                            String adr = order.getAdr().getZip() + " " + order.getAdr().getCity() + ", " + order.getAdr().getStreet() + " " + order.getAdr().getHouse();
                                                            rowEntities.add(new RowEntity(id, rmId, orderId, adr, true, false, r.nextDouble(), 1, "la", false, order.getLon(), order.getLat()));
                                                        } else {
                                                            rowEntities.add(new RowEntity(id, rmId, orderId, "", true, false, r.nextDouble(), 1, "la", false, order.getLon(), order.getLat()));
                                                        }
                                                        orderId++;
                                                        id++;

                                                        List<LoadingRow> loadingRows = new ArrayList<>();
                                                        for (BIN bin : order.getBin()) {
                                                            if (bin.getAmount() == null) {
                                                                LoadingRow loadingRow = new LoadingRow("type", "trash", 1, "status", false);
                                                                loadingRows.add(loadingRow);
                                                            } else {
                                                                LoadingRow loadingRow = new LoadingRow("type", "trash", bin.getAmount(), "status", false);
                                                                loadingRows.add(loadingRow);
                                                            }
                                                        }
                                                        expandableListDetail.put(orderId + "", loadingRows);
                                                    }
                                                    rmId++;
                                                }

                                                expandableListAdapter = new ExpandableListAdapter(MainActivity.this, rowEntities, expandableListDetail);
                                                runOnUiThread(new Runnable() {
                                                    @Override
                                                    public void run() {
                                                        expandableListView.setAdapter(expandableListAdapter);
                                                    }
                                                });

                                                break;
                                            } catch (XmlPullParserException e) {
                                                e.printStackTrace();
                                            }
                                        }
                                        all = true;
                                    }
                                }
                            }
                        }
                    }
                }
                if (all)
                    break;
            }