Refine search
/** * Reads the first line from the lock file and returns the results as a * string. * * @return the first line from the lock file; or null if the contents could * not be read */ private String readLockFile() { String msg = null; try (RandomAccessFile f = new RandomAccessFile(lockFile, "rw")) { msg = f.readLine(); } catch (IOException ex) { LOGGER.debug(String.format("Error reading lock file: %s", lockFile), ex); } return msg; }
try { // Connect to the pipe RandomAccessFile pipe = new RandomAccessFile("\\\\.\\pipe\\testpipe", "rw"); String echoText = "Hello word\n"; // write to pipe pipe.write ( echoText.getBytes() ); // read response String echoResponse = pipe.readLine(); System.out.println("Response: " + echoResponse ); pipe.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }
RandomAccessFile reader = new RandomAccessFile("/proc/stat", "r"); String load = reader.readLine(); load = reader.readLine(); reader.close();
public void run() throws Exception { Channel ch = bootstrap.bind(0).sync().channel(); long pointer = 0; for (;;) { long len = file.length(); if (len < pointer) { // file was reset pointer = len; } else if (len > pointer) { // Content was added RandomAccessFile raf = new RandomAccessFile(file, "r"); raf.seek(pointer); String line; while ((line = raf.readLine()) != null) { ch.writeAndFlush(new LogEvent(null, -1, file.getAbsolutePath(), line)); } pointer = raf.getFilePointer(); raf.close(); } try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.interrupted(); break; } } }
file.setWritable(true, false); ra = new RandomAccessFile(file, "rw"); String startPortStr = ra.readLine();
try { if (!lockFile.exists() && lockFile.createNewFile()) { file = new RandomAccessFile(lockFile, "rw"); lock = file.getChannel().lock(); file.writeBytes(magic); Thread.sleep(20); file.seek(0); final String current = file.readLine(); if (current != null && !current.equals(magic)) { lock.close();
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { Query post = RemoteAccess.evaluate(request); int length = post.get("length", 10000); final StringBuilder buffer = new StringBuilder(1000); File logfile = new File(DAO.data_dir, "loklak.log"); if (logfile.exists()) { try { RandomAccessFile raf = new RandomAccessFile(logfile, "r"); raf.seek(Math.max(0, raf.length() - length)); String line; while ((line = raf.readLine()) != null) { bufferappend(buffer, line); } raf.close(); } catch (IOException e) { e.printStackTrace(); } bufferappend(buffer, ""); } else { bufferappend(buffer, "file " + logfile.getAbsolutePath() + " does not exist"); } FileHandler.setCaching(response, 10); post.setResponse(response, "text/plain"); response.getOutputStream().write(UTF8.getBytes(buffer.toString())); post.finalize(); }
reader = new RandomAccessFile("/proc/stat", "r"); load = reader.readLine(); } catch (IOException ex) { ex.printStackTrace(); reader = new RandomAccessFile("/proc/" + pid + "/stat", "r"); line = reader.readLine(); } catch (IOException ex) { ex.printStackTrace();
/** * @throws Exception If failed. */ @Test public void testReadLineFromBinaryFile() throws Exception { File file = new File(FILE_PATH); file.deleteOnExit(); RandomAccessFile raf = new RandomAccessFile(file, "rw"); byte[] b = new byte[100]; Arrays.fill(b, (byte)10); raf.write(b); raf.writeBytes("swap-spaces/space1/b53b3a3d6ab90ce0268229151c9bde11|" + "b53b3a3d6ab90ce0268229151c9bde11|1315392441288" + U.nl()); raf.writeBytes("swap-spaces/space1/b53b3a3d6ab90ce0268229151c9bde11|" + "b53b3a3d6ab90ce0268229151c9bde11|1315392441288" + U.nl()); raf.write(b); raf.writeBytes("test" + U.nl()); raf.getFD().sync(); raf.seek(0); while (raf.getFilePointer() < raf.length()) { String s = raf.readLine(); X.println("String: " + s + ";"); X.println("String length: " + s.length()); X.println("File pointer: " + raf.getFilePointer()); } }
public static String getTotalRAM() { RandomAccessFile reader = null; String load = null; try { reader = new RandomAccessFile("/proc/meminfo", "r"); load = reader.readLine(); } catch (IOException ex) { ex.printStackTrace(); } finally { // Streams.close(reader); } return load; }
public static void removeNthLine(String f, int toRemove) throws IOException { RandomAccessFile raf = new RandomAccessFile(f, "rw"); // Leave the n first lines unchanged. for (int i = 0; i < toRemove; i++) raf.readLine(); // Shift remaining lines upwards. long writePos = raf.getFilePointer(); raf.readLine(); long readPos = raf.getFilePointer(); byte[] buf = new byte[1024]; int n; while (-1 != (n = raf.read(buf))) { raf.seek(writePos); raf.write(buf, 0, n); readPos += n; writePos += n; raf.seek(readPos); } raf.setLength(writePos); raf.close(); }
public static void removeFirstLine(String fileName) throws IOException { RandomAccessFile raf = new RandomAccessFile(fileName, "rw"); //Initial write position long writePosition = raf.getFilePointer(); raf.readLine(); // Shift the next lines upwards. long readPosition = raf.getFilePointer(); byte[] buff = new byte[1024]; int n; while (-1 != (n = raf.read(buff))) { raf.seek(writePosition); raf.write(buff, 0, n); readPosition += n; writePosition += n; raf.seek(readPosition); } raf.setLength(writePosition); raf.close(); }
String lastValue = ""; try { reader = new RandomAccessFile("/proc/meminfo", "r"); load = reader.readLine();
deletionHookAdded = true; RandomAccessFile file = new RandomAccessFile(lockF, "rws"); String jvmName = ManagementFactory.getRuntimeMXBean().getName(); FileLock res = null; } catch(OverlappingFileLockException oe) { String lockingJvmName = Path.WINDOWS ? "" : (" " + file.readLine()); LOG.error("It appears that another node {} has already locked the " + "storage directory: {}", lockingJvmName, root, oe);
RandomAccessFile f = new RandomAccessFile(filename, "r"); try { Log.d(LOGGING_TAG, "f.length() = " + f.length()); String contents = f.readLine(); if(!contents.isEmpty() && contents!=null) { try {
RandomAccessFile raf = new RandomAccessFile(file); ... raf.seek(position); raf.readLine(); ...
RandomAccessFile first = new RandomAccessFile("D:\\Temp.txt","r"); RandomAccessFile second = new RandomAccessFile("D:\\Temp.txt","r"); String line; String nextLine = second.readLine(); while (nextLine != null) { line = first.readLine(); nextLine = second.readLine(); if ((line.contains("[DesiredText]") && nextLine.isEmpty())) { pozycje.add(first.getFilePointer()); } }
public static void cat(File named) throws IOException { try (RandomAccessFile input = new RandomAccessFile(named, "r")) { String line = null; while ((line = input.readLine()) != null) { System.out.println(line); } } }
public String getRandomLineFromTheFile(File file) { final RandomAccessFile f = new RandomAccessFile(file, "r"); final long randomLocation = (long) (Math.random() * f.length()); f.seek(randomLocation); f.readLine(); return f.readLine(); }
public static String getTotalRAM() { RandomAccessFile reader = null; String load = null; try { reader = new RandomAccessFile("/proc/meminfo", "r"); load = reader.readLine(); } catch (IOException ex) { ex.printStackTrace(); } finally { // Streams.close(reader); } return load; }