Example #1
0
  private void ensureCapacity() throws IOException {
    if (offset >= BLOCK_SIZE) {
      // get the next block
      if (blockCount >= usedBlocks.length) {
        int[] blocks = new int[blockCount * 2];
        System.arraycopy(usedBlocks, 0, blocks, 0, usedBlocks.length);
        Arrays.fill(blocks, usedBlocks.length, blocks.length, -1);
        usedBlocks = blocks;
      }

      int nextBlockId = usedBlocks[blockCount];
      if (nextBlockId == -1) {
        nextBlockId = file.allocBlock();
        usedBlocks[blockCount] = nextBlockId;
      }

      // flush the current block into the disk
      if (blockId != -1) {
        BTreeUtils.integerToBytes(nextBlockId, bytes);
        file.writeBlock(blockId, bytes);
      }

      blockId = nextBlockId;
      blockCount++;

      Arrays.fill(bytes, (byte) 0);

      offset = 4;
    }
  }
Example #2
0
  public void close() throws IOException {
    if (blockId != -1) {
      BTreeUtils.integerToBytes(-1, bytes);
      file.writeBlock(blockId, bytes);
    }

    for (int i = blockCount; i < usedBlocks.length; i++) {
      int freeBlock = usedBlocks[i];
      if (freeBlock != -1) {
        file.freeBlock(freeBlock);
      }
    }
  }
Example #3
0
  public static void printType(NodeType type) {
    if (type instanceof NodeSynonym) {
      System.out.println("NodeSynonym: " + ((NodeSynonym) type).getID());
    } // System.out.println("NodeSynonym: " + ((NodeSynonym)type).getType());
    else if (type instanceof NodePLType) {
      System.out.println("PLType: " + ((NodePLType) type).getType());
    } else if (type instanceof NodePointer) {
      System.out.println("Puntero a");
      System.out.print("  ");
      printType(((NodePointer) type).getType());
    } else if (type instanceof NodeArray) {
      System.out.print("Arreglo de tamaƱo " + ((NodeArray) type).getSize() + " de tipo: ");
      printType(((NodeArray) type).getType());
    } else if (type instanceof NodeStructure) {
      NodeStructure structure = (NodeStructure) type;
      // List<NodeElement>	elements =	record.getElements(); CHANGE
      List<NodeElement> elements = structure.getElements();
      Iterator<NodeElement> iter = elements.iterator();

      // System.out.println("Estructura: " + "Nombre: " + record.getName()); CHANGE
      System.out.println("Estructura: " + "Nombre: " + structure.getName());

      int i = 1;
      NodeElement element;

      while (iter.hasNext()) {
        element = iter.next();

        System.out.println("Campo " + i + ": ");
        i++;

        // System.out.println("Nombre: " + (element.getName())); CHANGE
        System.out.println("Nombre: " + (element.getID()));
        System.out.print("Tipo: ");
        printType(element.getType());
      }
    } else if (type instanceof NodeList) {
      NodeList list = (NodeList) type;
      // List<NodeField>		fields	=	list.getFields(); CHANGE
      List<NodeElement> fields = list.getFields();
      // Iterator<NodeField> iter	= fields.iterator(); CHANGE
      Iterator<NodeElement> iter = fields.iterator();

      System.out.println("Lista");
      System.out.println("Nombre: " + list.getName());
      System.out.println("LinkType: " + list.getLinkType());
      System.out.println("LinkNexName: " + list.getLinkNextName());

      if (list.getLinkPrevName() != null) {
        System.out.println("LinkPrevName: " + list.getLinkPrevName());
      }

      int i = 1;

      NodeElement field;
      while (iter.hasNext()) {
        field = iter.next();
        System.out.println("Campo " + i + ":");
        i++;
        // System.out.println("Nombre: " + (field.getName())); CHANGE
        System.out.println("Nombre: " + (field.getID()));
        System.out.print("Tipo: ");
        printType(field.getType());
      }
      // if (list.getMemalloc() != null ) CHANGE
      if (list.getMemAlloc() != null) {
        System.out.println("MemallocFunction: ");
        // System.out.println(list.getMemalloc()); CHANGE
        System.out.println(list.getMemAlloc());
      }
    } else if (type instanceof NodeFile) {
      NodeFile file = (NodeFile) type;

      System.out.println("Archivo");
      System.out.println("Nombre: " + file.getName());
      System.out.println("Ruta: " + file.getPath());
      System.out.println("Delimitador: " + file.getDelimiter());

      if (file.getEof() != null) {
        System.out.println("EOF: " + file.getEof());
      }
      if (file.getEol() != null) {
        System.out.println("EOL: " + file.getEol());
      }
      if (file.getStructure() != null) {
        System.out.println("Estructura: " + file.getStructure());
      }
    } else if (type instanceof NodeDB) {
      NodeDB db = (NodeDB) type;
      List<NodeDBColumn> regs = db.getColumns();
      Iterator<NodeDBColumn> iter = regs.iterator();

      System.out.println("Base de Datos");
      System.out.println("DBMS: " + db.getDBMSID());
      // System.out.println("connectionID "		+ db.getConnID()); CHANGE
      System.out.println("connectionID " + db.getConnectionID());

      // System.out.println("Table name: "		+ db.getTable()); CHANGE
      System.out.println("Table name: " + db.getTableName());
      System.out.println("Registros:");

      int i = 1;

      while (iter.hasNext()) {
        NodeDBColumn rec = iter.next();
        System.out.println(
            "Registro " + i + ": " + rec.getColType() + " tipo: " + rec.getColType());
        i++;
      }
    }
  }
Example #4
0
 public NodeOutputStream(NodeFile file) throws IOException {
   this(file, new int[] {file.allocBlock()});
 }