List of usage examples for java.io RandomAccessFile readFully
public final void readFully(byte b[]) throws IOException
From source file:RawDataFromImageFilePDF.java
public static void main(String[] args) { Document document = new Document(); try {/*from w ww.ja va 2 s .c om*/ PdfWriter.getInstance(document, new FileOutputStream("RawDataFromImageFilePDF.pdf")); document.open(); RandomAccessFile rf = new RandomAccessFile("logo.png", "r"); int size = (int) rf.length(); byte imext[] = new byte[size]; rf.readFully(imext); rf.close(); Image img1 = Image.getInstance(imext); img1.setAbsolutePosition(50, 500); document.add(img1); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); }
From source file:RawDataFromImageFileAndManipulationPDF.java
public static void main(String[] args) { Document document = new Document(); try {/*from w w w. j a v a 2s .com*/ PdfWriter.getInstance(document, new FileOutputStream("RawDataFromImageFileAndManipulationPDF.pdf")); document.open(); RandomAccessFile rf = new RandomAccessFile("logo.png", "r"); int size = (int) rf.length(); byte imext[] = new byte[size]; rf.readFully(imext); rf.close(); for (int i = 0; i < imext.length; i++) { imext[i] = (byte) (imext[i] + 3); } Image img1 = Image.getInstance(100, 100, 3, 8, imext); img1.setAbsolutePosition(200, 200); document.add(img1); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); }
From source file:SenBench.java
public static void main(String[] args) { try {//from ww w . j a v a 2 s. c o m if (args.length == 0) { System.out.println("usage: java SenBench file [file ..]"); System.exit(2); } StringTagger tagger = StringTagger.getInstance(Locale.JAPANESE); long processed = 0; long nbytes = 0; long nchars = 0; long start = System.currentTimeMillis(); for (int a = 0; a < args.length; a++) { String text = ""; try { RandomAccessFile raf = new RandomAccessFile(args[a], "r"); byte[] buf = new byte[(int) raf.length()]; raf.readFully(buf); raf.close(); text = new String(buf, encoding); nbytes += buf.length; nchars += text.length(); } catch (IOException ioe) { log.error(ioe); continue; } long s_start = System.currentTimeMillis(); for (int c = 0; c < repeat; c++) doWork(tagger, text); long s_end = System.currentTimeMillis(); processed += (s_end - s_start); } long end = System.currentTimeMillis(); System.out.println("number of files: " + args.length); System.out.println("number of repeat: " + repeat); System.out.println("number of bytes: " + nbytes); System.out.println("number of chars: " + nchars); System.out.println("total time elapsed: " + (end - start) + " msec."); System.out.println("analysis time: " + (processed) + " msec."); } catch (Exception e) { e.printStackTrace(System.err); System.exit(1); } }
From source file:MeCabBench.java
public static void main(String[] args) { try {/* ww w . j ava 2s . co m*/ if (args.length == 0) { System.out.println("usage: java MeCabBench file [file ..]"); System.exit(2); } Tagger tagger = new Tagger(new String[] { "java", "-d", dicPath }); long processed = 0; long nbytes = 0; long nchars = 0; long start = System.currentTimeMillis(); for (int a = 0; a < args.length; a++) { String text = ""; try { RandomAccessFile raf = new RandomAccessFile(args[a], "r"); byte[] buf = new byte[(int) raf.length()]; raf.readFully(buf); raf.close(); text = new String(buf, encoding); nbytes += buf.length; nchars += text.length(); } catch (IOException ioe) { log.error(ioe); continue; } long s_start = System.currentTimeMillis(); for (int c = 0; c < repeat; c++) doWork(tagger, text); long s_end = System.currentTimeMillis(); processed += (s_end - s_start); } long end = System.currentTimeMillis(); System.out.println("number of files: " + args.length); System.out.println("number of repeat: " + repeat); System.out.println("number of bytes: " + nbytes); System.out.println("number of chars: " + nchars); System.out.println("total time elapsed: " + (end - start) + " msec."); System.out.println("analysis time: " + (processed) + " msec."); } catch (Exception e) { e.printStackTrace(System.err); System.exit(1); } }
From source file:Main.java
public static void main(String[] args) { try {// ww w.jav a 2s.c om String s = "Hello world from java2s.com"; RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); // write something in the file raf.writeUTF(s); // set the file pointer at 0 position raf.seek(0); // create an array equal to the length of raf byte[] arr = new byte[(int) raf.length()]; // read the file raf.readFully(arr); // create a new string based on arr String s2 = new String(arr); System.out.println(s2); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:org.commoncrawl.service.queryserver.master.S3Helper.java
public static void main(String[] args) { File arcFile = new File(args[0]); long offset = Long.parseLong(args[1]); long contentSize = Long.parseLong(args[2]); try {//w w w .ja va2 s . c o m RandomAccessFile fileHandle = new RandomAccessFile(arcFile, "r"); fileHandle.seek(Math.max(offset - 10, 0)); byte data[] = new byte[(int) contentSize + 10]; fileHandle.readFully(data); ByteBuffer buffer = ByteBuffer.wrap(data); buffer.position(0); int position = scanForGZIPHeader(buffer.slice()); buffer.position(position); StreamingArcFileReader reader = new StreamingArcFileReader(false); reader.available(buffer); ArcFileItem nextItem = reader.getNextItem(); System.out.println(nextItem.getUri()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
/** * RandomAccessFile seek and readFully/*from w w w. j a v a 2 s.co m*/ * * @param raf * @param index * @param buffer * @throws IOException */ private static void readFully(RandomAccessFile raf, long index, byte[] buffer) throws IOException { raf.seek(index); raf.readFully(buffer); }
From source file:Main.java
private static String readInstallationFile(File installation) throws IOException { RandomAccessFile f = new RandomAccessFile(installation, "r"); byte[] bytes = new byte[(int) f.length()]; f.readFully(bytes); f.close();//from ww w. jav a 2 s. co m return new String(bytes); }
From source file:Main.java
private static String readSaltFromFile(File file) throws IOException { RandomAccessFile accessFile = new RandomAccessFile(file, "r"); byte[] bs = new byte[(int) accessFile.length()]; accessFile.readFully(bs); accessFile.close();/* www . jav a 2 s .co m*/ return new String(bs); }
From source file:Main.java
private static String readInstallationFile(File installation) throws IOException { RandomAccessFile accessFile = new RandomAccessFile(installation, "r"); byte[] bs = new byte[(int) accessFile.length()]; accessFile.readFully(bs); accessFile.close();// w ww.j a v a 2 s .c om return new String(bs); }