Esempio n. 1
0
 private static void usage() {
   System.out.println("\nUSAGE: java " + classname + " [options]\n");
   System.out.println("Options:\n");
   System.out.println("-yuv = test YUV encoding/decoding support\n");
   System.out.println("-bi = test BufferedImage support\n");
   System.exit(1);
 }
Esempio n. 2
0
 public void keyPressed(KeyEvent key) {
   switch (key.getKeyChar()) {
     case KeyEvent.VK_ESCAPE:
       System.exit(0);
       break;
   }
 }
Esempio n. 3
0
  private void checkAndLaunchUpdate() {
    Log.i(LOG_FILE_NAME, "Checking for an update");

    int statusCode = 8; // UNEXPECTED_ERROR
    File baseUpdateDir = null;
    if (Build.VERSION.SDK_INT >= 8)
      baseUpdateDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
    else baseUpdateDir = new File(Environment.getExternalStorageDirectory().getPath(), "download");

    File updateDir = new File(new File(baseUpdateDir, "updates"), "0");

    File updateFile = new File(updateDir, "update.apk");
    File statusFile = new File(updateDir, "update.status");

    if (!statusFile.exists() || !readUpdateStatus(statusFile).equals("pending")) return;

    if (!updateFile.exists()) return;

    Log.i(LOG_FILE_NAME, "Update is available!");

    // Launch APK
    File updateFileToRun = new File(updateDir, getPackageName() + "-update.apk");
    try {
      if (updateFile.renameTo(updateFileToRun)) {
        String amCmd =
            "/system/bin/am start -a android.intent.action.VIEW "
                + "-n com.android.packageinstaller/.PackageInstallerActivity -d file://"
                + updateFileToRun.getPath();
        Log.i(LOG_FILE_NAME, amCmd);
        Runtime.getRuntime().exec(amCmd);
        statusCode = 0; // OK
      } else {
        Log.i(LOG_FILE_NAME, "Cannot rename the update file!");
        statusCode = 7; // WRITE_ERROR
      }
    } catch (Exception e) {
      Log.i(LOG_FILE_NAME, "error launching installer to update", e);
    }

    // Update the status file
    String status = statusCode == 0 ? "succeeded\n" : "failed: " + statusCode + "\n";

    OutputStream outStream;
    try {
      byte[] buf = status.getBytes("UTF-8");
      outStream = new FileOutputStream(statusFile);
      outStream.write(buf, 0, buf.length);
      outStream.close();
    } catch (Exception e) {
      Log.i(LOG_FILE_NAME, "error writing status file", e);
    }

    if (statusCode == 0) System.exit(0);
  }
Esempio n. 4
0
  public static void main(String args[]) {
    Connection c = null;
    PreparedStatement stmt = null;
    try {
      Class.forName("org.postgresql.Driver");
      c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "pdv", "pdv");
      System.out.println("Opened database successfully");
      List<String> results = new ArrayList<String>();
      File dir = new File("D:/jboss/eclipse/workspace/LTF");
      Iterator<File> files =
          FileUtils.iterateFilesAndDirs(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
      StopWatch timerAll = new StopWatch();
      timerAll.start();
      while (files.hasNext()) {
        File file = (File) files.next();
        if (file.isFile()) {
          StopWatch timeForAFile = new StopWatch();
          timeForAFile.start();
          String toDB = encodeFileToBase64Binary(file);
          String sql =
              "INSERT INTO test (file_id,file_name,file_data,file_date) VALUES (nextval('test_file_id_seq'),?,?,?)";
          stmt = c.prepareStatement(sql);

          stmt.setString(1, file.getAbsolutePath());
          stmt.setString(2, toDB);
          stmt.setDate(3, new java.sql.Date(Calendar.getInstance().getTimeInMillis()));
          stmt.executeUpdate();
          timeForAFile.stop();
          System.out.println(timeForAFile.toString());
        }
      }
      timerAll.stop();
      System.out.println("=================================================");
      System.out.println(timerAll.toString());

      stmt.close();
      /*
       * Statement statement = null; statement = c.createStatement();
       * ResultSet rs = statement.executeQuery(
       * "select file_data from test limit 1"); while (rs.next()) { String
       * encoded = rs.getString("file_data"); byte[] decoded =
       * Base64.getDecoder().decode(encoded); FileOutputStream fos = new
       * FileOutputStream("c:/temp/2.jpg"); fos.write(decoded);
       * fos.close(); }
       */

      c.close();
    } catch (Exception e) {
      System.err.println(e.getClass().getName() + ": " + e.getMessage());
      System.exit(0);
    }
    System.out.println("Table created successfully");
  }
Esempio n. 5
0
 public FilePlayback(String hostname, int port, String dataDir, double speedup, int blockSize) {
   this.hostname = hostname;
   this.port = port;
   this.dataDir = dataDir;
   this.speedup = speedup;
   this.blockSize = blockSize;
   client = new BufferClient();
   // Open the header/events/samples files
   try {
     initFiles(dataDir);
   } catch (FileNotFoundException e) {
     e.printStackTrace();
     System.exit(-1);
   }
 }
Esempio n. 6
0
File: ZCM.java Progetto: ZeroCM/zcm
  /**
   * Retrieve a default instance of ZCM using either the environment variable ZCM_DEFAULT_URL or the
   * default. If an exception occurs, System.exit(-1) is called.
   */
  public static ZCM getSingleton() {
    if (singleton == null) {
      try {
        // XXX: add back in capability to use the ZCM_DEFAULT_URL env variable
        //      as the default for getSingleton
        singleton = new ZCM();
      } catch (Exception ex) {
        System.err.println("ZCM singleton fail: " + ex);
        System.exit(-1);
        return null;
      }
    }

    return singleton;
  }
Esempio n. 7
0
 public static void main(String argv[]) {
   try {
     String testName = "javatest";
     boolean doyuv = false;
     for (int i = 0; i < argv.length; i++) {
       if (argv[i].equalsIgnoreCase("-yuv")) doyuv = true;
       if (argv[i].substring(0, 1).equalsIgnoreCase("-h") || argv[i].equalsIgnoreCase("-?"))
         usage();
       if (argv[i].equalsIgnoreCase("-bi")) {
         bi = true;
         testName = "javabitest";
       }
     }
     if (doyuv) yuv = YUVENCODE;
     doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_444, testName);
     doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_444, testName);
     doTest(41, 35, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_422, testName);
     doTest(35, 39, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_422, testName);
     doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_420, testName);
     doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_420, testName);
     doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_440, testName);
     doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_440, testName);
     doTest(35, 39, bi ? onlyGrayBI : onlyGray, TJ.SAMP_GRAY, testName);
     doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_GRAY, testName);
     doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_GRAY, testName);
     if (!doyuv && !bi) bufSizeTest();
     if (doyuv && !bi) {
       yuv = YUVDECODE;
       doTest(48, 48, onlyRGB, TJ.SAMP_444, "javatest_yuv0");
       doTest(35, 39, onlyRGB, TJ.SAMP_444, "javatest_yuv1");
       doTest(48, 48, onlyRGB, TJ.SAMP_422, "javatest_yuv0");
       doTest(39, 41, onlyRGB, TJ.SAMP_422, "javatest_yuv1");
       doTest(48, 48, onlyRGB, TJ.SAMP_420, "javatest_yuv0");
       doTest(41, 35, onlyRGB, TJ.SAMP_420, "javatest_yuv1");
       doTest(48, 48, onlyRGB, TJ.SAMP_440, "javatest_yuv0");
       doTest(35, 39, onlyRGB, TJ.SAMP_440, "javatest_yuv1");
       doTest(48, 48, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv0");
       doTest(35, 39, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv1");
       doTest(48, 48, onlyGray, TJ.SAMP_GRAY, "javatest_yuv0");
       doTest(39, 41, onlyGray, TJ.SAMP_GRAY, "javatest_yuv1");
     }
   } catch (Exception e) {
     e.printStackTrace();
     exitStatus = -1;
   }
   System.exit(exitStatus);
 }
Esempio n. 8
0
 private static void usage() {
   System.out.println("NAME");
   System.out.println("       HCIOTest - loop writing/reading/comparing data to/from files ");
   System.out.println("       mimicing Honeycomb's IO patterns");
   System.out.println();
   System.out.println("SYNOPSIS");
   System.out.println("       java HCIOTest Tempfile Permfile Size");
   System.err.println();
   System.out.println("DESCRIPTION");
   System.out.println("       HCIOTest takes three parameters:");
   System.out.println("         the complete path of the temporary file to be written");
   System.out.println("         the complete path of the permanent file");
   System.out.println("         the size of the file which must be a multiple of 4096");
   System.out.println();
   System.out.println("EXAMPLES");
   System.out.println("       java HCIOTest /data/tmp/tempfile0 /data/testfile0 102400");
   System.exit(1);
 }
Esempio n. 9
0
  @Override
  protected void onNewIntent(Intent intent) {
    if (checkLaunchState(LaunchState.GeckoExiting)) {
      // We're exiting and shouldn't try to do anything else just incase
      // we're hung for some reason we'll force the process to exit
      System.exit(0);
      return;
    }
    final String action = intent.getAction();
    if (ACTION_DEBUG.equals(action)
        && checkAndSetLaunchState(LaunchState.Launching, LaunchState.WaitForDebugger)) {

      mMainHandler.postDelayed(
          new Runnable() {
            public void run() {
              Log.i(LOG_FILE_NAME, "Launching from debug intent after 5s wait");
              setLaunchState(LaunchState.Launching);
              launch(null);
            }
          },
          1000 * 5 /* 5 seconds */);
      Log.i(LOG_FILE_NAME, "Intent : ACTION_DEBUG - waiting 5s before launching");
      return;
    }
    if (checkLaunchState(LaunchState.WaitForDebugger) || launch(intent)) return;

    if (Intent.ACTION_MAIN.equals(action)) {
      Log.i(LOG_FILE_NAME, "Intent : ACTION_MAIN");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(""));
    } else if (Intent.ACTION_VIEW.equals(action)) {
      String uri = intent.getDataString();
      GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
      Log.i(LOG_FILE_NAME, "onNewIntent: " + uri);
    } else if (ACTION_WEBAPP.equals(action)) {
      String uri = intent.getStringExtra("args");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
      Log.i(LOG_FILE_NAME, "Intent : WEBAPP - " + uri);
    } else if (ACTION_BOOKMARK.equals(action)) {
      String args = intent.getStringExtra("args");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(args));
      Log.i(LOG_FILE_NAME, "Intent : BOOKMARK - " + args);
    }
  }
Esempio n. 10
0
  public static void main(String[] args) throws IOException, InterruptedException {
    String hostname = "localhost";
    int port = 1972;
    int timeout = 5000;
    double speedup = 1;
    int blockSize = 1;
    String dataDir = null;

    if (args.length == 0) {
      System.out.print(usage);
      System.exit(-1);
    }
    if (args.length >= 1) {
      hostname = args[0];
      int sep = hostname.indexOf(':');
      if (sep > 0) {
        port = Integer.parseInt(hostname.substring(sep + 1, hostname.length()));
        hostname = hostname.substring(0, sep);
      }
    }
    if (args.length >= 2) {
      dataDir = args[1];
    }

    if (args.length >= 3) {
      try {
        speedup = Integer.parseInt(args[2]);
      } catch (NumberFormatException e) {
        speedup = 1;
      }
    }

    if (args.length >= 4) {
      try {
        blockSize = Integer.parseInt(args[3]);
      } catch (NumberFormatException e) {
        blockSize = 1;
      }
    }
    FilePlayback sp = new FilePlayback(hostname, port, dataDir, speedup, blockSize);
    sp.mainloop();
    sp.stop();
  }
Esempio n. 11
0
  /** @param args */
  public static void main(String[] args) {
    FileChannel fc = null;
    RandomAccessFile raf = null;
    // StringBuilder sb;

    if (args.length != 1) {
      System.out.println("Usage: Ntfs filename");
      System.exit(1);
    }
    /*
    sb = new StringBuilder();
    int[] foo = {129,4,229,33};
    for (int b: foo) {
        sb.insert(0,String.format("%02X", b));
    }
    System.out.println(sb.toString());
    System.exit(0);
    */
    try {
      raf = new RandomAccessFile(args[0], "r");
      fc = raf.getChannel();
      Filesystem fs = new Filesystem(fc);

      fs.demo();
      // fs.displayFs();
    } catch (FileNotFoundException x) {
      System.out.println("FNF exp: " + x.getMessage());
    } catch (IOException x) {
      System.out.println("IO exp: " + x.getMessage());
    } finally {
      if (raf != null)
        try {
          raf.close();
        } catch (IOException e) {
          e.printStackTrace(); // To change body of catch statement use File | Settings | File
          // Templates.
        }
    }
  }
Esempio n. 12
0
  public static void main(String[] argv) {
    if (argv.length != 3) {
      usage();
    }

    String tempFile = argv[0];
    String testFile = argv[1];
    int fileSize = Integer.valueOf(argv[2]).intValue();
    int exitcode = 0;
    int numRead;
    int numThisBuf;
    int numWritten;

    if ((fileSize <= 0) || (fileSize % 4096 != 0)) {
      System.out.println("Error: size is not a multiple of 4096!!!!!!");
      System.out.println();
      usage();
    }

    try {
      int bufSize = 4096;
      byte[] inBytes = new byte[bufSize];
      byte[] outBytes = new byte[bufSize];
      Random ioRandom = new Random(2006);
      ioRandom.nextBytes(outBytes);
      ByteBuffer inBuf = ByteBuffer.allocate(bufSize);
      ByteBuffer outBuf = ByteBuffer.wrap(outBytes);

      //
      // Loop forever
      //
      while (true) {
        //
        // Write the temporary file
        //
        FileOutputStream fos = new FileOutputStream(tempFile);
        FileChannel foc = fos.getChannel();
        numWritten = 0;
        while (numWritten < fileSize) {
          outBuf.clear(); // sets limit to capacity & position to zero
          while (outBuf.hasRemaining()) {
            numWritten += foc.write(outBuf);
          }
        }

        //
        // Move to permanent location
        //
        FileChannel srcChannel = new FileInputStream(tempFile).getChannel();
        FileChannel dstChannel = new FileOutputStream(testFile).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
        boolean success = (new File(tempFile)).delete();
        if (!success) {
          System.out.println("Warning: unable to delete temporary file");
        }

        //
        // Read and compare
        //
        FileInputStream fis = new FileInputStream(testFile);
        FileChannel fic = fis.getChannel();

        for (numRead = 0, numThisBuf = 0; numRead < fileSize; numThisBuf = 0) {
          inBuf.rewind(); // Set the buffer position to 0
          numThisBuf = fic.read(inBuf);
          while (numThisBuf < bufSize) {
            numThisBuf += fic.read(inBuf);
          }
          numRead += bufSize;
          inBuf.rewind(); // Set the buffer position to 0
          inBuf.get(inBytes);
          boolean same = Arrays.equals(inBytes, outBytes);
          if (same = false) {
            System.out.println("Data read does not equal data written at " + numRead + " bytes");
          }
        }
      }

    } catch (FileNotFoundException fnfe) {
      fnfe.printStackTrace(System.err);
      exitcode = 1;
      // break;
    } catch (SecurityException se) {
      se.printStackTrace(System.err);
      exitcode = 1;
      // break;
    } catch (Throwable t) {
      t.printStackTrace(System.err);
      exitcode = 1;
    }

    System.exit(exitcode);
  }
Esempio n. 13
0
  public void mainloop() {

    while (!client.isConnected()) {
      try {
        System.out.println("Connecting to " + hostname + ":" + port);
        client.connect(hostname, port);
      } catch (IOException e) {
      }
      if (!client.isConnected()) {
        System.out.println("Couldn't connect. waiting");
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          run = false;
          System.exit(-1);
        }
      }
    }

    // Load the header information in one go into a bytebuffer
    byte[] rawbytebuf = new byte[BUFFERSIZE];

    int n = 0;

    try {
      n = headerReader.read(rawbytebuf);
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Byte-buffer used to parse the byte-stream. Force native ordering
    ByteBuffer hdrBuf = ByteBuffer.wrap(rawbytebuf, 0, n);
    hdrBuf.order(ByteOrder.nativeOrder());
    Header hdr = new Header(hdrBuf);
    if (VERB > 0) {
      System.out.println("Sending header: " + hdr.toString());
    }
    hdr.nSamples = 0; // reset number of samples to 0

    try {
      client.putHeader(hdr);
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Interval between sending samples to the buffer
    int pktSamples = hdr.nChans * blockSize; // number data samples in each buffer packet
    int pktBytes = pktSamples * DataType.wordSize[hdr.dataType];
    int nsamp = 0; // sample counter
    int nblk = 0;
    int nevent = 0;
    byte[] samples = new byte[pktBytes];

    // Size of the event header: type,type_numel,val,val_numel,sample,offset,duration,bufsz
    int evtHdrSz = DataType.wordSize[DataType.INT32] * 8;
    byte[] evtRawBuf = new byte[BUFFERSIZE]; // buffer to hold complete event structure

    // Byte-buffer used to parse the byte-stream. Force native ordering
    ByteBuffer evtBuf = ByteBuffer.wrap(evtRawBuf);
    evtBuf.order(ByteOrder.nativeOrder());
    int payloadSz = 0;
    int evtSample = 0;
    int evtSz = 0;
    long sample_ms = 0;
    long starttime_ms = java.lang.System.currentTimeMillis();
    long elapsed_ms = 0;
    long print_ms = 0;

    // Now do the data forwarding
    boolean eof = false;

    while (!eof
        && run) { // The run switch allows control of stopping the thread and getting out of the
      // loop
      // Read one buffer packets worth of samples
      // increment the cursor position
      if (VERB > 0 && elapsed_ms > print_ms + 500) {
        print_ms = elapsed_ms;
        System.out.println(
            nblk
                + " "
                + nsamp
                + " "
                + nevent
                + " "
                + (elapsed_ms / 1000)
                + " (blk,samp,event,sec)\r");
      }

      // read and write the samples
      try {
        n = dataReader.read(samples);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (n <= 0) {
        eof = true;
        break;
      } // stop if run out of samples

      try {
        client.putRawData(blockSize, hdr.nChans, hdr.dataType, samples);
      } catch (IOException e) {
        e.printStackTrace();
      }

      // update the sample count
      nsamp += blockSize;
      while (evtSample <= nsamp) {
        if (evtSample > 0) { // send the current event
          try {
            client.putRawEvent(evtRawBuf, 0, evtSz);
          } catch (IOException e) {
            e.printStackTrace();
          }
          nevent++;
        }

        // read the next event
        try {
          n = eventReader.read(evtRawBuf, 0, evtHdrSz); // read the fixed size header
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (n <= 0) {
          eof = true;
          break;
        }
        evtSample = ((ByteBuffer) evtBuf.position(4 * 4)).getInt(); // sample index for this event
        payloadSz = ((ByteBuffer) evtBuf.position(4 * 7)).getInt(); // payload size for this event
        evtSz = evtHdrSz + payloadSz;

        // read the variable part
        try {
          n = eventReader.read(evtRawBuf, evtHdrSz, payloadSz);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (n <= 0) {
          eof = true;
          break;
        }

        // print the event we just read
        if (VERB > 1) {
          ByteBuffer tmpev = ByteBuffer.wrap(evtRawBuf, 0, evtSz);
          tmpev.order(evtBuf.order());
          BufferEvent evt = new BufferEvent(tmpev);
          System.out.println("Read Event: " + evt);
        }
      }

      // sleep until the next packet should be send OR EOF
      /*when to send the next sample */
      sample_ms = (long) ((float) (nsamp * 1000) / hdr.fSample / (float) speedup);
      elapsed_ms = java.lang.System.currentTimeMillis() - starttime_ms; // current time
      if (sample_ms > elapsed_ms)
        try {
          Thread.sleep(sample_ms - elapsed_ms);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      nblk++;
    }

    stop();
  }