/** 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); }
@Override public IFormatReader loadReader() throws IOException, ClassNotFoundException { int cSize = loadStream.readInt(); byte[] cArr = new byte[cSize]; loadStream.readFully(cArr); // Assuming proper encoding. @SuppressWarnings("unchecked") Class<IFormatReader> c = (Class<IFormatReader>) Class.forName( new String(cArr, Constants.ENCODING)); int rSize = loadStream.readInt(); byte[] rArr = new byte[rSize]; loadStream.readFully(rArr); return readerFromBytes(c, rArr); }
@Override public IFormatReader loadReader() throws IOException, ClassNotFoundException { int cSize = loadStream.readInt(); byte[] cArr = new byte[cSize]; loadStream.readFully(cArr); // Assuming proper encoding. @SuppressWarnings("unchecked") Class<IFormatReader> c = (Class<IFormatReader>) Class.forName( new String(cArr, Constants.ENCODING)); int rSize = loadStream.readInt(); byte[] rArr = new byte[rSize]; loadStream.readFully(rArr); return readerFromBytes(c, rArr); }
/** * 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); }
/** * Reads the contents of the given file into a string. * * @param id name of the file to read * this can be any name supported by Location, * not necessarily a file on disk * @return the complete contents of the specified file * @throws IOException if the file cannot be read or is larger than 2GB * @see Location#getMappedId(String) */ public static String readFile(String id) throws IOException { RandomAccessInputStream in = new RandomAccessInputStream(id); long idLen = in.length(); if (idLen > Integer.MAX_VALUE) { throw new IOException("File too large"); } int len = (int) idLen; byte[] b = new byte[len]; in.readFully(b); in.close(); String data = new String(b, Constants.ENCODING); b = null; return data; }
public long[] toArray() throws IOException { long fp = stream.getFilePointer(); stream.seek(start); byte[] rawBytes = new byte[size * 8]; stream.readFully(rawBytes); stream.seek(fp); return (long[]) DataTools.makeDataArray(rawBytes, 8, false, stream.isLittleEndian()); }
public long[] toArray() throws IOException { long fp = stream.getFilePointer(); stream.seek(start); byte[] rawBytes = new byte[size * 8]; stream.readFully(rawBytes); stream.seek(fp); return (long[]) DataTools.makeDataArray(rawBytes, 8, false, stream.isLittleEndian()); }
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) { } }
try(RandomAccessInputStream is = new RandomAccessInputStream(file.getAbsolutePath())) { is.readFully(buf);
try(RandomAccessInputStream is = new RandomAccessInputStream(file.getAbsolutePath())) { is.readFully(buf);
private byte[] readPixelBlock(RandomAccessInputStream s, long offset) throws IOException { s.order(true); s.seek(offset); int checkLength = s.readInt(); int check = s.readInt(); if (check != 3) { s.seek(offset); return null; } s.skipBytes(8); // currently unknown int uidLength = s.readInt(); String uid = s.readString(uidLength); LOGGER.debug("reading pixel block with uid = {}", uid); if (checkLength != uidLength + 12) { s.seek(offset); return null; } int pixelBytes = s.readInt(); s.skipBytes(4); // currently unknown byte[] pixels = new byte[pixelBytes]; s.readFully(pixels); return pixels; }
private byte[] readPixelBlock(RandomAccessInputStream s, long offset) throws IOException { s.order(true); s.seek(offset); int checkLength = s.readInt(); int check = s.readInt(); if (check != 3) { s.seek(offset); return null; } s.skipBytes(8); // currently unknown int uidLength = s.readInt(); String uid = s.readString(uidLength); LOGGER.debug("reading pixel block with uid = {}", uid); if (checkLength != uidLength + 12) { s.seek(offset); return null; } int pixelBytes = s.readInt(); s.skipBytes(4); // currently unknown byte[] pixels = new byte[pixelBytes]; s.readFully(pixels); return pixels; }
in.readFully(bytes);
s.readFully(buf);
is.readFully(buf); return buf;