0

Is there an equivalent of below Java code in in Swift > 3?

int i = LibUtils.StreamReadInt(is);

byte[] aa = new byte[i];


is.read(aa, 0, i);

here, the code for StreamReadInt is

public static int StreamReadInt(InputStream st) {

int i = 0;
    try {
        DataInputStream ds = new DataInputStream(st);
        i = ds.readInt();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return i;
}
shashwat
  • 7,851
  • 9
  • 57
  • 90
Rahul Verma
  • 688
  • 5
  • 17
  • `DataInputStream` uses a binary format. If you can avoid it, you shouldn't rely on a binary format for data exchange between Java and another language. Simple text files, XML or JSON would be far better. – vanje Jul 12 '17 at 15:01
  • @Vanje, Thanks for the information. But i am working on a live project for iOS and i must use the same decoding and decryption to match it with downloaded data. I got some help from here https://stackoverflow.com/questions/44549840/swift-converting-a-byte-array-to-integers. I just want to know the definition of readInt, as it is giving the different information every time after is.read(aa, 0, i);. – Rahul Verma Jul 12 '17 at 16:58
  • You can find the exact definition of the binary format in interface [DataInput](https://docs.oracle.com/javase/8/docs/api/java/io/DataInput.html). – vanje Jul 12 '17 at 18:29

0 Answers0