private boolean readTape(InputStream stream) {
    byte[] start = new byte[32];
    dirNames.clear();
    dirEntries.clear();
    type = TAPE;
    try {
      DataInputStream reader = new DataInputStream(stream);
      reader.readFully(start);

      String st = new String(start);
      if (st.startsWith("C64")) {
        System.out.println("Tape Archive found:");
        reader.readFully(start);
        int max = start[3]*256 + start[2];
        int used = start[5]*256 + start[4];
        if (used == 0) used = 1;
        String name = "";
        System.out.println("Type: " + start[0]*256 + start[1]);
        System.out.println("Max Entries: " + max);
        System.out.println("Used Entries: " + used);
        for (int i = 8; i < 32; i++)
          name = name + (char) start[i];
        System.out.println("Name: " + name);

        int startAdr, endAdr, offset;
        for (int i = 0; i < used; i++) {
          reader.readFully(start);
          startAdr = (start[2]&0xff) +
          (start[3]&0xff) * 256;
          endAdr = (start[4]&0xff) +
          (start[5]&0xff) * 256;
          offset = (start[8]&0xff) +
          (start[9]&0xff) * 256;
          System.out.println("---------------------");
          System.out.println("Entry: " + i);
          System.out.println("File Type: " + start[0]);
          System.out.println("1541 Type: " + start[1]);
          System.out.println("Start Adr: " + startAdr);
          System.out.println("End Adr: " + endAdr + " -> size = " +
              (endAdr - startAdr));
          System.out.println("Offset: " + offset);
          name = "";
          for (int j = 16; j < 32; j++)
            name = name + (char) start[j];
          System.out.println("File Name: " + name);
          DirEntry entry = new DirEntry(name, offset -
              32 * (max + 2), startAdr,
              endAdr - startAdr, start[1]);
          dirNames.add(entry);
          dirEntries.put(name, entry);
        }
        // Skip all empty entries!!!
        for (int i = used; i < max; i++) {
          reader.readFully(start);
        }

        int sector = 0;
        int numRead;
        while((numRead = readSector(reader, sector)) == 256)
          sector++;
        noBytes = sector * 256 + numRead;
        System.out.println("Read " + noBytes + " program data");

        // dumpSector(sectors[0]);
      }
      return true;
    } catch (Exception e) {
      System.out.println("Error while reading tape");
    }
    return false;
  }