Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m looking for a good explanation of substring with File.reader or File.writer

ID: 3646980 • Letter: I

Question

I'm looking for a good explanation of substring with File.reader or File.writer in Java.

i.e +Buffer.substring(0,15)

Links to relevant websites would be appreciated.

Explanation / Answer

Here is how to do this in java in 8.1.6. 8.1.6 added lots of new security features so this would be a little different in 8.1.5 but mostly the same. We need to start by granting some privs. I'm going to grant as little as I have to get allow us to execute the program /usr/bin/ps. As SYS or some appropriately priveleged user, we will execute: sys@DEV816> begin 2 dbms_java.grant_permission 3 ('RT_TEST', 4 'java.io.FilePermission', 5 '/usr/bin/ps', 6 'execute'); 7 8 dbms_java.grant_permission 9 ('RT_TEST', 10 'java.lang.RuntimePermission', 11 '*', 12 'writeFileDescriptor' ); 13 end; 14 / PL/SQL procedure successfully completed. That allows our user RT_TEST to successfully execute that program. We could have allowed it to execute /usr/bin/* or * or whatever -- I'm just letting it execute that one program. Now, RT_TEST would create in its schema: rt_test@DEV816> create or replace and compile 2 java source named "Util" 3 as 4 import java.io.*; 5 import java.lang.*; 6 7 public class Util extends Object 8 { 9 10 public static int RunThis(String[] args) 11 { 12 Runtime rt = Runtime.getRuntime(); 13 int rc = -1; 14 15 try 16 { 17 Process p = rt.exec(args[0]); 18 19 int bufSize = 4096; 20 BufferedInputStream bis = 21 new BufferedInputStream(p.getInputStream(), bufSize); 22 int len; 23 byte buffer[] = new byte[bufSize]; 24 25 // Echo back what the program spit out 26 while ((len = bis.read(buffer, 0, bufSize)) != -1) 27 System.out.write(buffer, 0, len); 28 29 rc = p.waitFor(); 30 } 31 catch (Exception e) 32 { 33 e.printStackTrace(); 34 rc = -1; 35 } 36 finally 37 { 38 return rc; 39 } 40 } 41 } 42 / Java created. rt_test@DEV816> create or replace 2 function RUN_CMD( p_cmd in varchar2) return number 3 as 4 language java 5 name 'Util.RunThis(java.lang.String[]) return integer'; 6 /

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote