/** Read a string of up to length n. */ public String readString(int n) throws IOException { int avail = available(); if (n > avail) n = avail; byte[] b = new byte[n]; readFully(b); return new String(b, encoding); }
/** * Read a null-terminated string. Read at most n characters if the null * character is not found. */ private static String readCString(RandomAccessInputStream s, int n) throws IOException { int avail = s.available(); if (n > avail) n = avail; byte[] b = new byte[n]; s.readFully(b); int i; for (i = 0; i < b.length && b[i] != 0; i++) { } return new String(b, 0, i, Constants.ENCODING); }
/** * Read a null-terminated string. Read at most n characters if the null * character is not found. */ private static String readCString(RandomAccessInputStream s, int n) throws IOException { int avail = s.available(); if (n > avail) n = avail; byte[] b = new byte[n]; s.readFully(b); int i; for (i = 0; i < b.length && b[i] != 0; i++) { } return new String(b, 0, i, Constants.ENCODING); }
/** * Read a string of up to length n. * * @param n the number of bytes to read * @return a string representing the read bytes, using the default encoding * @throws IOException if an error occurred during reading * @see #setEncoding(String) */ public String readString(int n) throws IOException { int avail = available(); if (n > avail) n = avail; byte[] b = new byte[n]; readFully(b); return new String(b, encoding); }
/** * Reads a byte array of the given length byte by byte. Returns a string * using the set encoding. * * @param n The length of the array. * @return See above * @throws IOException Thrown if an error occurred while reading the data. */ public String readByteToString(int n) throws IOException { n = (int) Math.min(available(), n); byte[] bytes = new byte[n]; readFully(bytes); StringBuffer newString = new StringBuffer(); for (byte b : bytes) { int v = b & 0xff; if (v > 0x7f) { newString.append(Character.toChars(v)); } else { newString.append((char) b); } } String s = newString.toString(); return new String(s.getBytes(encoding), encoding); }
/** * Reads a byte array of the given length byte by byte. Returns a string * using the set encoding. * * @param n The length of the array. * @return See above * @throws IOException Thrown if an error occurred while reading the data. * @see #setEncoding(String) */ public String readByteToString(int n) throws IOException { n = (int) Math.min(available(), n); byte[] bytes = new byte[n]; readFully(bytes); StringBuffer newString = new StringBuffer(); for (byte b : bytes) { int v = b & 0xff; if (v > 0x7f) { newString.append(Character.toChars(v)); } else { newString.append((char) b); } } String s = newString.toString(); return new String(s.getBytes(encoding), encoding); }
public void initialize(RandomAccessInputStream in, int y, int h, int imageWidth) { this.in = in; tiles = new TileCache(y, h); preprocess(this.in); try { Toolkit toolkit = Toolkit.getDefaultToolkit(); byte[] data = new byte[this.in.available()]; this.in.readFully(data); Image image = toolkit.createImage(data); ImageProducer producer = image.getSource(); consumer = new TileConsumer(producer, y, h); producer.startProduction(consumer); while (producer.isConsumer(consumer)); } catch (IOException e) { } }