Package org.tc65sh.util

Examples of org.tc65sh.util.ByteArray


        File f = new File(filepath);
        FileInputStream in = new FileInputStream(f);
        byte[] buf = new byte[(int) f.length()];
        in.read(buf);
        in.close();
        ByteArray content = new ByteArray(buf);
        FileInfo fi = new FileInfo(false, f.getName(), (int) f.length(), new Date(f.lastModified()));
        FileHolder fh = new FileHolder(fi, content);
        return fh;
    }
View Full Code Here


    public static final byte RESPONSE_CREATED = (byte)0x21;
    public static final byte RESPONSE_BADREQUEST = (byte)0x40;
    public static final byte RESPONSE_FINAL = (byte)0x80;
   
  public static ByteArray encodeUtf16String(String str) {
    ByteArray b = new ByteArray();
    for( int i=0 ; i<str.length() ; i++ ) {
      b.append(0x00);
      b.append(str.charAt(i));
    }
    return b;
  }
View Full Code Here

    return sb.toString();
  }
   
  public static ByteArray encodeDateTime(Date d) {
    String s = encodeXmlDateTime(d);
    ByteArray b = new ByteArray(s,"ISO-8859-1");
    return b;
  }
View Full Code Here

    serialOut = serialPort.getOutputStream();
  }
 
  public void initDevice() throws IOException {
    Log.debug(this.getClass(), "initializing device connection");             
    sendByteArray(new ByteArray("AT\r","ISO-8859-1"));
    waitForATResponseWithOK(DEFAULT_INTERNAL_AT_RESPONSE_TIMEOUT, true);
                sendByteArray(new ByteArray("ATE\r","ISO-8859-1"));
    waitForATResponseWithOK(DEFAULT_INTERNAL_AT_RESPONSE_TIMEOUT, true);
    sendByteArray(new ByteArray("AT\r","ISO-8859-1"));
    waitForATResponseWithOK(DEFAULT_INTERNAL_AT_RESPONSE_TIMEOUT, true);
    sendByteArray(new ByteArray("AT\r","ISO-8859-1"));
    waitForATResponseWithOK(DEFAULT_INTERNAL_AT_RESPONSE_TIMEOUT, true);
    sendByteArray(new ByteArray("ATI\r","ISO-8859-1"));
    ByteArray response = waitForATResponseWithOK(DEFAULT_INTERNAL_AT_RESPONSE_TIMEOUT, true);
    Log.debug(this.getClass(), " " + response.toPrintableString());
  }
View Full Code Here

    Log.debug(this.getClass(), " " + response.toPrintableString());
  }
       
    public boolean checkForTC65() throws IOException {
        try {
            sendByteArray(new ByteArray("AT\r", "ISO-8859-1"));
            waitForATResponseWithOK(DEFAULT_INTERNAL_AT_RESPONSE_TIMEOUT, true);
        } catch (IOException ex) {
            Log.debug(this.getClass(), "checkForTc65: " + ex);
            return false;
        }
View Full Code Here

 
  public void waitForSysstart(long timeout) throws IOException {
    Log.debug(getClass(), "waiting for sysstart");
    boolean foundSysstart = false;
    long t1 = System.currentTimeMillis();
    ByteArray byteArray = new ByteArray();
    while( ! foundSysstart ) {
      int readCount = receiveIntoByteArray(byteArray);
      if ( readCount > 0 ) {
        if ( byteArray.toPrintableString().contains("^SYSSTART") ) {
          foundSysstart = true;
        }
      } else {
        sleep(100);
      }
View Full Code Here

  public List<FileInfo> obexGetFolderListing() throws IOException {
    if ( ! inObexMode ) {
      openObexMode();
    }
    String typeUid = "x-obex/folder-listing";
    ByteArray typeHeader = new ByteArray();
    typeHeader.append(Obex.HEADER_TYPE);
    typeHeader.append(Obex.shortToBytes(3+typeUid.length()));
    typeHeader.append(typeUid, "ISO-8859-1");
    ByteArray req = new ByteArray();
    req.append(Obex.REQUEST_GET | Obex.REQUEST_FINAL);
    req.append(Obex.shortToBytes(3+typeHeader.length()));
    req.append(typeHeader);
    sendByteArray(req);
    ByteArray body = receiveBodyToEnd();
    Log.debug(this.getClass(), new String(body.getBuffer(), "ISO-8859-1"));
    String xml = new String(body.getBuffer(), "ISO-8859-1");
    String[] lines = xml.split("\n");
    ArrayList<FileInfo> fileInfos = new ArrayList<FileInfo>();
    for( String line : lines ) {
      line = line.trim();
      FileInfo fi = parseFolderListingLine(line);
View Full Code Here

  public void obexDeleteFile(String filename) throws IOException {
    if ( ! inObexMode ) {
      openObexMode();
    }
    ByteArray obexFilename = Obex.encodeUtf16String(filename);
    ByteArray nameHeader = new ByteArray();
    nameHeader.append(Obex.HEADER_NAME);
    nameHeader.append(Obex.shortToBytes(3+obexFilename.length()));
    nameHeader.append(obexFilename);
    ByteArray req = new ByteArray();
    req.append(Obex.REQUEST_PUT | Obex.REQUEST_FINAL);
    req.append(Obex.shortToBytes(3+nameHeader.length()));
    req.append(nameHeader);
    sendByteArray(req);
    ByteArray response = receiveObexResponse(DEFAULT_OBEX_RESPONSE_TIMEOUT);
    validateResponseCode(response);
  }
View Full Code Here

  public void obexEraseDisk() throws IOException {
    if ( ! inObexMode ) {
      openObexMode();
    }
    ByteArray appParamsHeader = new ByteArray();
    appParamsHeader.append(Obex.HEADER_APP_PARAMETERS);
    appParamsHeader.append(Obex.shortToBytes(5));
    appParamsHeader.append(0x31);
    appParamsHeader.append(0x00);
    ByteArray req = new ByteArray();
    req.append(Obex.REQUEST_PUT | Obex.REQUEST_FINAL);
    req.append(Obex.shortToBytes(3+appParamsHeader.length()));
    req.append(appParamsHeader);
    sendByteArray(req);
    ByteArray response = receiveObexResponse(DEFAULT_ERASE_DISK_TIMEOUT); // may take a long time
    validateResponseCode(response);
  }
View Full Code Here

  public FileHolder obexGetFile(String filename) throws IOException {
    if ( ! inObexMode ) {
      openObexMode();
    }
    ByteArray obexFilename = Obex.encodeUtf16String(filename);
    ByteArray header = new ByteArray();
    header.append(Obex.HEADER_NAME);   
    header.append(Obex.shortToBytes(3+obexFilename.length()));
    header.append(obexFilename);
    ByteArray req = new ByteArray();
    req.append(Obex.REQUEST_GET | Obex.REQUEST_FINAL)
    req.append(Obex.shortToBytes(3+header.length()));
    req.append(header);
    sendByteArray(req);
    ByteArray body = receiveBodyToEnd();
    FileHolder result = new FileHolder(new FileInfo(false, filename, body.length(), null), body);
    return result;
  }
View Full Code Here

TOP

Related Classes of org.tc65sh.util.ByteArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.