fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.io.BufferedInputStream;
  7. import java.io.FileInputStream;
  8.  
  9. class Struct{
  10. private byte []a;
  11. private byte []b;
  12. byte []buf;
  13. Struct(){
  14. a=new byte[4];
  15. b=new byte[4];
  16. buf=new byte[a.length+b.length];
  17. }
  18.  
  19. String GetA(){
  20. System.arraycopy(buf, 0, a, 0, a.length);
  21. return new String(a);
  22. }
  23.  
  24. long GetB(){
  25. System.arraycopy(buf, a.length, b, 0, b.length);
  26. int len=b.length;
  27. int[] c=new int[len];
  28. int[] d=new int[len];
  29.  
  30. for(int i=0;i<len;i++){
  31. c[i]=((int)b[i] & 0xFF);
  32. d[i]=c[i];
  33. }
  34. long x=0;
  35. for(int i=0;i<len;i++){
  36. c[i]=d[len-1-i];// byte order reverse
  37. x+=((long)c[i]<<(8*(len-1-i)));
  38. }
  39.  
  40. return x;
  41. }
  42. }
  43.  
  44. class Ideone
  45. {
  46. public static void main (String[] args) throws java.lang.Exception
  47. {
  48. Struct st=new Struct();
  49. try{
  50. bis=new BufferedInputStream(new FileInputStream("test"));
  51. for(int i=0;i<3;i++){
  52. bis.read(st.buf);
  53. System.out.println(st.GetA()+"\n");
  54. System.out.println(st.GetB()+"\n");
  55.  
  56. }
  57. }
  58. catch(Exception e){
  59.  
  60. }
  61. }
  62. }
Success #stdin #stdout 0.12s 320576KB
stdin
Standard input is empty
stdout
Standard output is empty