public static void main(String[] Args) {
    // System.setProperty("KEY", "HNY81514525MALVIYA");
    // Map<String, String> env = System.getenv();
    // for (String envName : env.keySet())
    // System.out.format("%s = %s%n", envName, env.get(envName));

    // reg add HKCU\\Environment /v developer /d \"Honey Keny Malviya" /f"

    try {
      String PERSONAL_FOLDER_CMD = "reg query HKCU\\Environment /v developer";
      String REGSTR_TOKEN = "REG_SZ";
      Process process = Runtime.getRuntime().exec(PERSONAL_FOLDER_CMD);
      StreamReader reader = new StreamReader(process.getInputStream());
      reader.start();
      process.waitFor();
      reader.join();
      String result = reader.getResult();
      int p = result.indexOf(REGSTR_TOKEN);
      if (p == -1) return;
      System.out.println(result.substring(p + REGSTR_TOKEN.length()).trim());
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
  }
Example #2
0
  @Test
  public void timezone_without_id() throws Exception {
    StreamReader reader =
        new StreamReaderImpl() {
          @Override
          protected ICalendar _readNext() {
            ICalendar ical = new ICalendar();

            VTimezone timezone = new VTimezone(null);
            {
              StandardTime standard = new StandardTime();
              standard.setDateStart(new DateTimeComponents(2014, 9, 1, 2, 0, 0, false));
              standard.setTimezoneOffsetFrom(new UtcOffset(true, 10, 0));
              standard.setTimezoneOffsetTo(new UtcOffset(true, 9, 0));
              timezone.addStandardTime(standard);

              DaylightSavingsTime daylight = new DaylightSavingsTime();
              daylight.setDateStart(new DateTimeComponents(2014, 1, 1, 2, 0, 0, false));
              daylight.setTimezoneOffsetFrom(new UtcOffset(true, 9, 0));
              daylight.setTimezoneOffsetTo(new UtcOffset(true, 10, 0));
              timezone.addDaylightSavingsTime(daylight);
            }
            ical.addComponent(timezone);

            return ical;
          }
        };

    ICalendar ical = reader.readNext();
    TimezoneInfo tzinfo = reader.getTimezoneInfo();
    assertEquals(0, tzinfo.getComponents().size());
    assertEquals(1, ical.getComponents(VTimezone.class).size());
    assertWarnings(1, reader);
  }
Example #3
0
  private String readRegistry(String location, String key) {
    String result = null;
    Process process = null;
    try {
      process = Runtime.getRuntime().exec("reg query " + '"' + location + "\" /v " + key);

      StreamReader reader = new StreamReader(process.getInputStream());
      reader.start();
      process.waitFor();
      reader.join();

      String[] parsed = reader.getResult().split("\\s+");

      if (parsed != null) {
        for (int i = 0; i < parsed.length; i++) {
          if (parsed[i].toLowerCase().indexOf("%systemdrive%") != -1
              || parsed[i]
                      .toLowerCase()
                      .indexOf(System.getenv("SystemDrive").toLowerCase() + File.separator)
                  != -1) {
            result = parsed[i];
          } else {
            if (result != null) {
              result += " " + parsed[i];
            }
          }

          // if (parsed[i].toLowerCase().indexOf("%systemdrive%") ==
          // -1) {
          // if (result != null) {
          // result += " " + parsed[i];
          // }
          // } else {
          // result = parsed[i];
          // }
        }
      }

      if (result == null) {
        result = System.getenv("SystemDrive") + File.separator;
      }

      // if (parsed.length > 1) {
      // result = parsed[parsed.length - 1];
      // }
      // System.out.println(result);
      result = result.replace("%SystemDrive%", System.getenv("SystemDrive"));
    } catch (Exception e) {
      result = System.getenv("SystemDrive") + File.separator;
    }

    return result;
  }
 /** read inputstream before process.waitfor(). keep threads never hangs up. */
 @Override
 public void run() {
   try {
     StreamReader reader = new StreamReader(process.getInputStream());
     reader.start();
     reader.join(readTimeOut);
     process.waitFor();
   } catch (InterruptedException ignore) {
     return;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
  @Override
  public void startStripe(StreamSources dictionaryStreamSources, List<ColumnEncoding> encoding)
      throws IOException {
    presentStreamSource = missingStreamSource(BooleanStream.class);

    readOffset = 0;
    nextBatchSize = 0;

    presentStream = null;

    rowGroupOpen = false;

    for (StreamReader structField : structFields) {
      structField.startStripe(dictionaryStreamSources, encoding);
    }
  }
  @Override
  public void startRowGroup(StreamSources dataStreamSources) throws IOException {
    presentStreamSource =
        dataStreamSources.getStreamSource(streamDescriptor, PRESENT, BooleanStream.class);

    readOffset = 0;
    nextBatchSize = 0;

    presentStream = null;

    rowGroupOpen = false;

    for (StreamReader structField : structFields) {
      structField.startRowGroup(dataStreamSources);
    }
  }
 /** Start the process and attach handlers */
 public void go() {
   /*
    * String launch = "/bin/bash -c \"env - CASSANDRA_CONF=" + instanceConf.getAbsolutePath()
    * +" JAVA_HOME="+ "/usr/java/jdk1.7.0_45 " + cstart.getAbsolutePath().toString() + " -f \"";
    */
   LOGGER.debug(Arrays.asList(this.launchArray));
   Runtime rt = Runtime.getRuntime();
   try {
     process = rt.exec(launchArray);
   } catch (IOException e1) {
     LOGGER.error(e1.getMessage());
     throw new RuntimeException(e1);
   }
   waitForShutdown = new CountDownLatch(1);
   InputStream output = process.getInputStream();
   InputStream error = process.getErrorStream();
   waitForTheEnd =
       new Thread() {
         public void run() {
           try {
             exitValue.set(process.waitFor());
             waitForShutdown.countDown();
             for (ProcessHandler h : processHandlers) {
               h.handleTermination(exitValue.get());
             }
           } catch (InterruptedException e) {
             waitForShutdown.countDown();
           }
         }
       };
   StreamReader outReader = new StreamReader(output);
   for (LineHandler h : this.out) {
     outReader.addHandler(h);
   }
   outstreamThread = new Thread(outReader);
   StreamReader errReader = new StreamReader(error);
   for (LineHandler h : this.err) {
     errReader.addHandler(h);
   }
   errstreamThread = new Thread(errReader);
   waitForTheEnd.start();
   outstreamThread.start();
   errstreamThread.start();
 }
Example #8
0
  public void testReadNumberOfBytesWithClosedInput() throws Exception {
    startReading(new ReadCountBytes(100));

    for (int i = 0; i < 50; i++) writeToPipe("*");
    output.close();
    finishReading();

    assertEquals("bytes consumed", 50, reader.numberOfBytesConsumed());
    assertEquals("bytes returned", 50, byteResult.length);
  }
 {
     if ((long)i != streamReader.skip(i))
     {
         if (Log.isLoggable("ImageHeaderParser", 3))
         {
             Log.d("ImageHeaderParser", (new StringBuilder()).append("Unable to skip enough data for type=").append(word0).toString());
         }
         return null;
     }
     continue; /* Loop/switch isn't completed */
 }
Example #10
0
 public void testEofReadLine() throws Exception {
   writeToPipe("one line\ntwo lines\nthree lines");
   output.close();
   assertFalse(reader.isEof());
   reader.readLine();
   assertFalse(reader.isEof());
   reader.readLine();
   assertFalse(reader.isEof());
   reader.readLine();
   assertTrue(reader.isEof());
 }
Example #11
0
 public void testEofReadCount() throws Exception {
   writeToPipe("abcdefghijklmnopqrstuvwxyz");
   output.close();
   assertFalse(reader.isEof());
   reader.read(10);
   assertFalse(reader.isEof());
   reader.read(16);
   assertFalse(reader.isEof());
   reader.read(1);
   assertTrue(reader.isEof());
 }
Example #12
0
 public void testEofReadUpTo() throws Exception {
   writeToPipe("mark one, mark two, the end");
   output.close();
   assertFalse(reader.isEof());
   reader.readUpTo("one");
   assertFalse(reader.isEof());
   reader.readUpTo("two");
   assertFalse(reader.isEof());
   reader.readUpTo("three");
   assertTrue(reader.isEof());
 }
Example #13
0
  public void testBytesConsumed() throws Exception {
    writeToPipe("One line\r\n12345abc-boundary");
    assertEquals(0, reader.numberOfBytesConsumed());

    reader.readLine();
    assertEquals(10, reader.numberOfBytesConsumed());

    reader.read(5);
    assertEquals(15, reader.numberOfBytesConsumed());

    reader.readUpTo("-boundary");
    assertEquals(27, reader.numberOfBytesConsumed());
  }
Example #14
0
  /**
   * Executes a command as {@code user}. Saves the stdout/stderr in the corresponding fields and
   * returns the return code of the child process.
   *
   * @param cmd The command to execute
   * @param data The data to send to the stdin of the process
   * @param timelimt How many seconds the command can run
   * @param memlimit How many megabytes the command can use
   */
  private int exec(String cmdS, String data, int timelimit, int memlimit) throws Exception {
    ArrayList<String> cmd = new ArrayList<String>(cmdPrefix);
    cmd.add("-m");
    cmd.add("" + memlimit);
    cmd.add("-c");
    cmd.add("" + timelimit);
    cmd.add("-w");
    cmd.add("" + (3 * timelimit + 1));
    cmd.add("-x");
    cmd.add(cmdS);
    String tmp = "";
    for (String cs : cmd) tmp += " \"" + cs + "\"";
    log.fine("exec " + tmp);
    ProcessBuilder pb = new ProcessBuilder(cmd);
    pb.directory(workDir);
    Process p = pb.start();
    OutputStreamWriter writer = new OutputStreamWriter(p.getOutputStream());
    StreamReader rOut = new StreamReader(p.getInputStream());
    StreamReader rErr = new StreamReader(p.getErrorStream());
    rOut.start();
    rErr.start();

    // TODO I think this may block for big tests. Check and Fix.
    // send and receive data "in parallel"
    writer.write(data);
    writer.flush();
    writer.close();
    rOut.join();
    rErr.join();
    stdout = rOut.result;
    stderr = rErr.result;
    if (rOut.exception != null) throw rOut.exception;
    if (rErr.exception != null) throw rErr.exception;

    // log.finer("out: " + stdout);
    // log.finer("err: " + stderr);
    // log.finer("done exec");
    return p.waitFor();
  }
    private byte[] getExifSegment()
        throws IOException
    {
_L6:
        short word0 = streamReader.getUInt8();
        if (word0 == 255) goto _L2; else goto _L1
Example #16
0
 public static void copyBytes(InputStream input, OutputStream output) throws Exception {
   StreamReader reader = new StreamReader(input);
   while (!reader.isEof()) output.write(reader.readBytes(1000));
 }
Example #17
0
  @Override
  public Block readBlock(Type type) throws IOException {
    if (!rowGroupOpen) {
      openRowGroup();
    }

    if (readOffset > 0) {
      if (presentStream != null) {
        // skip ahead the present bit reader, but count the set bits
        // and use this as the skip size for the field readers
        readOffset = presentStream.countBitsSet(readOffset);
      }
      for (StreamReader structField : structFields) {
        structField.prepareNextRead(readOffset);
      }
    }

    List<Type> typeParameters = type.getTypeParameters();

    boolean[] nullVector = new boolean[nextBatchSize];
    Block[] blocks = new Block[typeParameters.size()];
    if (presentStream == null) {
      for (int i = 0; i < typeParameters.size(); i++) {
        StreamReader structField = structFields[i];
        structField.prepareNextRead(nextBatchSize);
        blocks[i] = structField.readBlock(typeParameters.get(i));
      }
    } else {
      int nullValues = presentStream.getUnsetBits(nextBatchSize, nullVector);
      if (nullValues != nextBatchSize) {
        for (int i = 0; i < typeParameters.size(); i++) {
          StreamReader structField = structFields[i];
          structField.prepareNextRead(nextBatchSize - nullValues);
          blocks[i] = structField.readBlock(typeParameters.get(i));
        }
      } else {
        for (int i = 0; i < typeParameters.size(); i++) {
          blocks[i] = typeParameters.get(i).createBlockBuilder(new BlockBuilderStatus(), 0).build();
        }
      }
    }

    // Build offsets for array block (null valued have no positions)
    int[] offsets = new int[nextBatchSize];
    offsets[0] = (nullVector[0] ? 0 : typeParameters.size());
    for (int i = 1; i < nextBatchSize; i++) {
      offsets[i] = offsets[i - 1] + (nullVector[i] ? 0 : typeParameters.size());
    }

    // Struct is represented as an array block holding an interleaved block
    InterleavedBlock interleavedBlock = new InterleavedBlock(blocks);
    ArrayBlock arrayBlock =
        new ArrayBlock(
            interleavedBlock,
            Slices.wrappedIntArray(offsets),
            0,
            Slices.wrappedBooleanArray(nullVector));

    readOffset = 0;
    nextBatchSize = 0;

    return arrayBlock;
  }
Example #18
0
  @Test
  public void timezones() throws Exception {
    StreamReader reader =
        new StreamReaderImpl() {
          @Override
          protected ICalendar _readNext() {
            ICalendar ical = new ICalendar();

            VTimezone timezone = new VTimezone("tz");
            {
              StandardTime standard = new StandardTime();
              standard.setDateStart(new DateTimeComponents(2014, 9, 1, 2, 0, 0, false));
              standard.setTimezoneOffsetFrom(new UtcOffset(true, 10, 0));
              standard.setTimezoneOffsetTo(new UtcOffset(true, 9, 0));
              timezone.addStandardTime(standard);

              DaylightSavingsTime daylight = new DaylightSavingsTime();
              daylight.setDateStart(new DateTimeComponents(2014, 1, 1, 2, 0, 0, false));
              daylight.setTimezoneOffsetFrom(new UtcOffset(true, 9, 0));
              daylight.setTimezoneOffsetTo(new UtcOffset(true, 10, 0));
              timezone.addDaylightSavingsTime(daylight);
            }
            ical.addComponent(timezone);

            TestProperty floating = new TestProperty(icalDate("2014-09-21T10:22:00"));
            context.addFloatingDate(floating, floating.date);
            ical.addProperty(floating);

            String tzid = timezone.getTimezoneId().getValue();
            TestProperty timezoned = new TestProperty(icalDate("2014-10-01T13:07:00"));
            timezoned.getParameters().setTimezoneId(tzid);
            context.addTimezonedDate(tzid, timezoned, timezoned.date);
            ical.addProperty(timezoned);

            tzid = timezone.getTimezoneId().getValue();
            timezoned = new TestProperty(icalDate("2014-08-01T13:07:00"));
            timezoned.getParameters().setTimezoneId(tzid);
            context.addTimezonedDate(tzid, timezoned, timezoned.date);
            ical.addProperty(timezoned);

            tzid = timezone.getTimezoneId().getValue();
            timezoned = new TestProperty(icalDate("2013-12-01T13:07:00"));
            timezoned.getParameters().setTimezoneId(tzid);
            context.addTimezonedDate(tzid, timezoned, timezoned.date);
            ical.addProperty(timezoned);

            tzid = "/America/New_York";
            timezoned = new TestProperty(icalDate("2014-07-04T09:00:00"));
            timezoned.getParameters().setTimezoneId(tzid);
            context.addTimezonedDate(tzid, timezoned, timezoned.date);
            ical.addProperty(timezoned);

            tzid = "America/New_York";
            timezoned = new TestProperty(icalDate("2014-07-04T09:00:00"));
            timezoned.getParameters().setTimezoneId(tzid);
            context.addTimezonedDate(tzid, timezoned, timezoned.date);
            ical.addProperty(timezoned);

            tzid = "foobar";
            timezoned = new TestProperty(icalDate("2014-06-11T14:00:00"));
            timezoned.getParameters().setTimezoneId(tzid);
            context.addTimezonedDate(tzid, timezoned, timezoned.date);
            ical.addProperty(timezoned);

            return ical;
          }
        };

    ICalendar ical = reader.readNext();
    TimezoneInfo tzinfo = reader.getTimezoneInfo();

    Collection<VTimezone> components = tzinfo.getComponents();
    assertEquals(1, components.size());
    assertEquals(0, ical.getComponents(VTimezone.class).size());

    VTimezone component = components.iterator().next();
    Iterator<TestProperty> it = ical.getProperties(TestProperty.class).iterator();

    // floating-time property
    TestProperty property = it.next();
    assertTrue(tzinfo.isFloating(property));
    assertNull(tzinfo.getComponent(property));
    assertNull(tzinfo.getTimeZone(property));
    assertNull(property.getParameters().getTimezoneId());
    assertEquals(date("2014-09-21 10:22:00"), property.date);

    // timezoned property
    property = it.next();
    assertFalse(tzinfo.isFloating(property));
    assertEquals(component, tzinfo.getComponent(property));
    assertTrue(tzinfo.getTimeZone(property) instanceof ICalTimeZone);
    assertNull(property.getParameters().getTimezoneId());
    assertEquals(utc("2014-10-01 04:07:00"), property.date);

    // timezoned property
    property = it.next();
    assertFalse(tzinfo.isFloating(property));
    assertEquals(component, tzinfo.getComponent(property));
    assertTrue(tzinfo.getTimeZone(property) instanceof ICalTimeZone);
    assertNull(property.getParameters().getTimezoneId());
    assertEquals(utc("2014-08-01 03:07:00"), property.date);

    // timezoned property
    property = it.next();
    assertFalse(tzinfo.isFloating(property));
    assertEquals(component, tzinfo.getComponent(property));
    assertTrue(tzinfo.getTimeZone(property) instanceof ICalTimeZone);
    assertNull(property.getParameters().getTimezoneId());
    assertEquals(utc("2013-12-01 04:07:00"), property.date);

    // property with Olsen TZID
    property = it.next();
    assertFalse(tzinfo.isFloating(property));
    assertNull(tzinfo.getComponent(property));
    assertEquals(TimeZone.getTimeZone("America/New_York"), tzinfo.getTimeZone(property));
    assertNull(property.getParameters().getTimezoneId());
    assertEquals(utc("2014-07-04 13:00:00"), property.date);

    // property with Olsen TZID that doesn't point to a VTIMEZONE component
    property = it.next();
    assertFalse(tzinfo.isFloating(property));
    assertNull(tzinfo.getComponent(property));
    assertEquals(TimeZone.getTimeZone("America/New_York"), tzinfo.getTimeZone(property));
    assertNull(property.getParameters().getTimezoneId());
    assertEquals(utc("2014-07-04 13:00:00"), property.date);

    // property with TZID that doesn't point to a VTIMEZONE component
    property = it.next();
    assertFalse(tzinfo.isFloating(property));
    assertNull(tzinfo.getComponent(property));
    assertNull(tzinfo.getTimeZone(property));
    assertEquals("foobar", property.getParameters().getTimezoneId());
    assertEquals(date("2014-06-11 14:00:00"), property.date);

    assertFalse(it.hasNext());
    assertWarnings(2, reader);
  }
Example #19
0
  @Override
  public synchronized int read(ExtractorInput input, PositionHolder seekPosition)
      throws IOException, InterruptedException {
    // read packet header

    // messageId  uint16  2 bytes
    // frameType  uint16  2 bytes
    // length     uint32  4 bytes

    scratch.read(input, 4);

    int messageId = scratch.getU16();
    int frameType = scratch.getU16();

    // check for format packet
    if (messageId == Connection.XVDR_STREAM_CHANGE) {
      Log.d(TAG, "stream change packet received");
      scratch.peek(input, 512);
      updateStreamReaders(scratch);

      int bytesRead = scratch.position();
      Log.d(TAG, "skipping " + bytesRead + " bytes (stream change packet)");
      input.skipFully(bytesRead);

      // reset position reference
      position.reset();
      return RESULT_CONTINUE;
    }

    // exit if we didn't receive a stream packet
    if (messageId != Connection.XVDR_STREAM_MUXPKT) {
      Log.d(TAG, "unknown message id: " + messageId);
      return RESULT_CONTINUE;
    }

    // read stream packet header

    // pid        uint16  2 bytes
    // pts        int64   8 bytes
    // dts        int64   8 bytes
    // duration   uint32  4 bytes
    // length     uint32  4 bytes

    scratch.read(input, 26);

    int pid = scratch.getU16();
    long pts = scratch.getS64();
    long dts = scratch.getS64();
    scratch.getU32();

    int size = (int) scratch.getU32(); // size of encapsulated stream data

    StreamReader reader = streamManager.get(pid);

    // unknown stream ?
    if (reader == null) {
      input.skipFully(size);
      input.skipFully(8);
      return RESULT_CONTINUE;
    }

    // convert TS -> timeUs
    long timeUs = position.adjustTimestamp(pts);

    // consume stream data
    reader.consume(input, size, timeUs, C.BUFFER_FLAG_KEY_FRAME);

    // get current position
    // position   uint64  8 bytes

    scratch.read(input, 8);

    long pos = scratch.getU64();

    // sanity check if position is within the range
    if (position.getStartPosition() < pos && pos < position.getEndPosition()) {
      position.set(timeUs, pos);
    }

    return RESULT_CONTINUE;
  }
Example #20
0
 public void testCopyBytesUpTo() throws Exception {
   ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
   writeToPipe("some bytes--boundary");
   reader.copyBytesUpTo("--boundary", outputStream);
   assertEquals("some bytes", outputStream.toString());
 }
Example #21
0
 public void tearDown() throws Exception {
   output.close();
   reader.close();
 }