List of usage examples for java.io FileInputStream skip
public long skip(long n) throws IOException
n
bytes of data from the input stream. From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("C:/String.txt"); FileInputStream fin = new FileInputStream(file); int ch;/* w w w .j a va 2 s. c o m*/ // skip first 10 bytes fin.skip(10); while ((ch = fin.read()) != -1) { System.out.print((char) ch); } }
From source file:Main.java
public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream("C://test.txt"); // skip bytes from file input stream fis.skip(4); // read bytes from this stream int i = fis.read(); // converts integer to character char c = (char) i; System.out.print("Character read: " + c); }
From source file:Main.java
public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream(FileDescriptor.in); // skip bytes from file input stream fis.skip(4); // read bytes from this stream int i = fis.read(); // converts integer to character char c = (char) i; System.out.print("Character read: " + c); }
From source file:Main.java
public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream(new File("C://test.txt")); // skip bytes from file input stream fis.skip(4); // read bytes from this stream int i = fis.read(); // converts integer to character char c = (char) i; System.out.print("Character read: " + c); }
From source file:thv.th.reader.LevelReader.java
public static THMap read(FileInputStream mapStream, ABuffer tabStream, FileInputStream chunkStream, THPalette palette, Color background) throws IOException { Vector<BufferedImage> tiles = ChunksReader.readAll(chunkStream, tabStream, palette, background); THMap result = new THMap(); result.setPlayers(mapStream.read()); mapStream.skip(33); for (int y = 0; y < 128; ++y) { for (int x = 0; x < 128; ++x) { int pos = (int) mapStream.getChannel().position(); int anim = EndianUtils.readSwappedShort(mapStream); int layer0id = mapStream.read(); int layer1id = mapStream.read(); int layer2id = mapStream.read(); layer0id = tileMap[layer0id]; layer1id = tileMap[layer1id]; layer2id = tileMap[layer2id]; BufferedImage l0 = tiles.elementAt(layer0id); BufferedImage l1 = null; BufferedImage l2 = null; if (layer1id > 0) { l1 = tiles.elementAt(layer1id); }//from ww w . j a v a 2s. c om if (layer2id > 0) { l2 = tiles.elementAt(layer2id); } mapStream.skip(3); Tile tile = new Tile(anim, l0, l1, l2, pos); result.setTile(x, y, tile); } } for (int y = 0; y < 128; ++y) { for (int x = 0; x < 128; ++x) { int pid = EndianUtils.readSwappedShort(mapStream); result.getTile(x, y).setParcel(pid); } } mapStream.close(); return result; }
From source file:azkaban.utils.FileIOUtils.java
public static Pair<Integer, Integer> readUtf8File(File file, int offset, int length, OutputStream stream) throws IOException { byte[] buffer = new byte[length]; FileInputStream fileStream = new FileInputStream(file); long skipped = fileStream.skip(offset); if (skipped < offset) { fileStream.close();//from www . j a va2 s. c om return new Pair<Integer, Integer>(0, 0); } BufferedInputStream inputStream = null; try { inputStream = new BufferedInputStream(fileStream); inputStream.read(buffer); } finally { IOUtils.closeQuietly(inputStream); } Pair<Integer, Integer> utf8Range = getUtf8Range(buffer, 0, length); stream.write(buffer, utf8Range.getFirst(), utf8Range.getSecond()); return new Pair<Integer, Integer>(offset + utf8Range.getFirst(), utf8Range.getSecond()); }
From source file:azkaban.utils.FileIOUtils.java
public static LogData readUtf8File(File file, int fileOffset, int length) throws IOException { byte[] buffer = new byte[length]; FileInputStream fileStream = new FileInputStream(file); long skipped = fileStream.skip(fileOffset); if (skipped < fileOffset) { fileStream.close();/* www .j av a2s . co m*/ return new LogData(fileOffset, 0, ""); } BufferedInputStream inputStream = null; int read = 0; try { inputStream = new BufferedInputStream(fileStream); read = inputStream.read(buffer); } finally { IOUtils.closeQuietly(inputStream); } if (read <= 0) { return new LogData(fileOffset, 0, ""); } Pair<Integer, Integer> utf8Range = getUtf8Range(buffer, 0, read); String outputString = new String(buffer, utf8Range.getFirst(), utf8Range.getSecond()); return new LogData(fileOffset + utf8Range.getFirst(), utf8Range.getSecond(), outputString); }
From source file:azkaban.utils.FileIOUtils.java
public static JobMetaData readUtf8MetaDataFile(File file, int fileOffset, int length) throws IOException { byte[] buffer = new byte[length]; FileInputStream fileStream = new FileInputStream(file); long skipped = fileStream.skip(fileOffset); if (skipped < fileOffset) { fileStream.close();// w ww . j a v a 2 s .c o m return new JobMetaData(fileOffset, 0, ""); } BufferedInputStream inputStream = null; int read = 0; try { inputStream = new BufferedInputStream(fileStream); read = inputStream.read(buffer); } finally { IOUtils.closeQuietly(inputStream); } if (read <= 0) { return new JobMetaData(fileOffset, 0, ""); } Pair<Integer, Integer> utf8Range = getUtf8Range(buffer, 0, read); String outputString = new String(buffer, utf8Range.getFirst(), utf8Range.getSecond()); return new JobMetaData(fileOffset + utf8Range.getFirst(), utf8Range.getSecond(), outputString); }
From source file:thv.th.reader.FramesReader.java
public static THFrame readByIndex(int frameIndex, FileInputStream frameStream, FileInputStream listStream, FileInputStream elementStream, File tabFile, File chunksFile, THPalette palette) throws IOException { frameStream.getChannel().position(frameIndex * 10); int listIndex = EndianUtils.readSwappedInteger(frameStream) * 2; int width = frameStream.read(); int height = frameStream.read(); if (width == 0 || height == 0) return null; frameStream.skip(1); int flags = frameStream.read(); int nextFrame = EndianUtils.readSwappedShort(frameStream); THFrame res = new THFrame(frameIndex, width, height, flags, nextFrame, chunksFile, tabFile, palette); Vector<Integer> elementList = new Vector<Integer>(); listStream.getChannel().position(listIndex); while (true) { int elementIndex = EndianUtils.readSwappedShort(listStream); if (elementIndex == -1) break; SpriteElement element = SpriteElementReader.readByIndex(elementStream, elementIndex); res.addElement(element);/*from w w w.j a va2s. co m*/ } return res; }
From source file:com.xlythe.engine.theme.Theme.java
public static Typeface getFont(Context context, String name) { String key = getKey(context) + "_" + name; if (TYPEFACE_MAP.containsKey(key)) { return TYPEFACE_MAP.get(key); }//w w w. j a v a 2 s . co m String[] extensions = { ".ttf", ".otf" }; for (String s : extensions) { try { // Use cursor loader to grab font String url = getPackageName() + ".FileProvider/" + name + s; Uri uri = Uri.parse("content://" + url); ContentResolver cr = context.getContentResolver(); AssetFileDescriptor a = cr.openAssetFileDescriptor(uri, null); FileInputStream in = new FileInputStream(a.getFileDescriptor()); in.skip(a.getStartOffset()); File file = new File(context.getCacheDir(), name + s); file.createNewFile(); FileOutputStream fOutput = new FileOutputStream(file); byte[] dataBuffer = new byte[1024]; int readLength = 0; while ((readLength = in.read(dataBuffer)) != -1) { fOutput.write(dataBuffer, 0, readLength); } in.close(); fOutput.close(); // Try/catch for broken fonts Typeface t = Typeface.createFromFile(file); TYPEFACE_MAP.put(key, t); return TYPEFACE_MAP.get(key); } catch (Exception e) { // Do nothing here } } TYPEFACE_MAP.put(key, null); return TYPEFACE_MAP.get(key); }