OSDN Git Service

lejos_NXJ_win32_0_5_0beta.zip
[nxt-jsp/lejos_nxj.git] / nxtOSEK / lejos_nxj / src / java / classes / lejos / nxt / comm / USBInputStream.java
1 package lejos.nxt.comm;
2
3 import java.io.*;
4
5 /**
6  * Implements an InputStream over USB.
7  * 
8  * @author Lawrie Griffiths
9  *
10  */
11 public class USBInputStream extends InputStream {
12         private byte buf[] = new byte[64];
13         private int bufIdx = -1, bufSize = -1;
14         
15         public int read() {
16                 if (bufIdx == bufSize) {
17                         do {
18                                 bufSize = USB.usbRead(buf, 64);
19                         } while (bufSize == 0);
20                         bufIdx = 0;
21                 }
22                 
23             return buf[bufIdx++] & 0xFF;
24         }
25 }
26