kopia lustrzana https://github.com/felHR85/UsbSerial
added chunked stream methods
rodzic
1823f2b167
commit
f52c67a134
|
@ -54,6 +54,18 @@ public class SerialInputStream extends InputStream
|
|||
return device.syncRead(b, timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte b[], int off, int len)
|
||||
{
|
||||
if (off == 0 && len == b.length) {
|
||||
return read(b);
|
||||
}
|
||||
byte[] slice = new byte[len];
|
||||
int ret = device.syncRead(slice, timeout);
|
||||
System.arraycopy(slice, 0, b, off, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
if(bufferSize > 0)
|
||||
|
|
|
@ -25,6 +25,18 @@ public class SerialOutputStream extends OutputStream
|
|||
device.syncWrite(b, timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte b[], int off, int len)
|
||||
{
|
||||
if (off == 0 && len == b.length) {
|
||||
write(b);
|
||||
return;
|
||||
}
|
||||
byte[] slice = new byte[len];
|
||||
System.arraycopy(b, off, slice, 0, len);
|
||||
device.syncWrite(slice, timeout);
|
||||
}
|
||||
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue