/** * Build a new BHT from an Input Stream. * If the file is bad, it throws CorruptedFileException. * Precondition : the BufferedInputStream must be valid and place just before the beginning of the tree. * Complexity : O(n) with n = the number of nodes. */ public static BinaryHuffmanTree buildIn (BufferedInputStream in) throws CorruptedFileException { try { int octet = in.read(); if (octet == 0) { BinaryHuffmanTree noeud = new BinaryHuffmanTree(buildIn(in),buildIn(in)); return noeud; } else if (octet == 1) { return new BinaryHuffmanTree(in.read()); } else { throw new CorruptedFileException ("The tree wasn't well build.", CorruptedFileException.CorruptedType.BadTree); } } catch (IOException ex) { throw new CorruptedFileException ("End of file found too early.", CorruptedFileException.CorruptedType.CuttedFile); } }