/** 调用包装类显示各基本数据类型的取值范围。 */
  public static void main(String[] args) {
    // Byte类的常用方法和常量
    System.out.println("byte的数据总数:" + Math.pow(2, 8));
    System.out.println("byte的取值范围:" + Byte.MIN_VALUE + "~" + Byte.MAX_VALUE);
    byte bMax = Byte.parseByte("127");
    System.out.println(bMax);

    // Short类的常用方法和常量
    System.out.println("short的数据总数:" + Math.pow(2, 16));
    System.out.println("short的取值范围:" + Short.MIN_VALUE + "~" + Short.MAX_VALUE);
    short shortValue = Short.parseShort("1000");
    System.out.println(shortValue);

    // Integer类的常用方法和常量
    System.out.println("int的数据总数:" + Math.pow(2, 32));
    System.out.println("int的取值范围:" + Integer.MIN_VALUE + "~" + Integer.MAX_VALUE);
    int intValue = Integer.parseInt("2000000");
    System.out.println(intValue);
    String binaryValue = Integer.toBinaryString(16);
    String hexValue = Integer.toHexString(16);
    String octalValue = Integer.toOctalString(16);
    System.out.println("16转换为二进制:" + binaryValue);
    System.out.println("16转换为十六进制数:" + hexValue);
    System.out.println("16转换为八进制数:" + octalValue);

    // Long类的常用方法和常量
    System.out.println("long的数据总数:" + Math.pow(2, 64));
    System.out.println("long的取值范围:" + Long.MIN_VALUE + "~" + Long.MAX_VALUE);
    long longValue = Long.parseLong("2000000");
    System.out.println(intValue);
    binaryValue = Long.toBinaryString(16);
    hexValue = Long.toHexString(16);
    octalValue = Long.toOctalString(16);
    System.out.println("16转换为二进制:" + binaryValue);
    System.out.println("16转换为十六进制数:" + hexValue);
    System.out.println("16转换为八进制数:" + octalValue);
    // Float类的常用方法和常量

    System.out.println("float的数据总数:" + Math.pow(2, 32));
    System.out.println("float的取值范围:" + Float.MIN_VALUE + "~" + Float.MAX_VALUE);
    float floatValue = Long.parseLong("2000000");
    System.out.println(floatValue);
    hexValue = Float.toHexString(16);
    System.out.println("16转换为十六进制数:" + hexValue);

    // Double类的常用方法和常量
    System.out.println("double的数据总数:" + Math.pow(2, 64));
    System.out.println("double的取值范围:" + Double.MIN_VALUE + "~" + Double.MAX_VALUE);
    double doubleValue = Long.parseLong("2000000");
    System.out.println(doubleValue);
    binaryValue = Long.toBinaryString(16);
    hexValue = Long.toHexString(16);
    octalValue = Long.toOctalString(16);
    System.out.println("16转换为二进制:" + binaryValue);
    System.out.println("16转换为十六进制数:" + hexValue);
    System.out.println("16转换为八进制数:" + octalValue);
  }
 /* (non-Javadoc)
  * @see com.aptana.ide.core.ftp.BaseFTPConnectionFileManager#changeFilePermissions(org.eclipse.core.runtime.IPath, long, org.eclipse.core.runtime.IProgressMonitor)
  */
 @Override
 protected void changeFilePermissions(IPath path, long permissions, IProgressMonitor monitor)
     throws CoreException, FileNotFoundException {
   if (chmodSupported == Boolean.FALSE) {
     return;
   }
   try {
     IPath dirPath = path.removeLastSegments(1);
     changeCurrentDir(dirPath);
     Policy.checkCanceled(monitor);
     chmodSupported =
         ftpClient.site(
             "CHMOD "
                 + Long.toOctalString(permissions)
                 + " "
                 + path.lastSegment()); // $NON-NLS-1$ //$NON-NLS-2$
   } catch (FileNotFoundException e) {
     throw e;
   } catch (OperationCanceledException e) {
     throw e;
   } catch (Exception e) {
     throw new CoreException(
         new Status(Status.ERROR, FTPPlugin.PLUGIN_ID, "Set permissions failed", e));
   } finally {
     monitor.done();
   }
 }
  private void writeAsciiLong(final long number, final int length, final int radix)
      throws IOException {
    final StringBuilder tmp = new StringBuilder();
    String tmpStr;
    if (radix == 16) {
      tmp.append(Long.toHexString(number));
    } else if (radix == 8) {
      tmp.append(Long.toOctalString(number));
    } else {
      tmp.append(Long.toString(number));
    }

    if (tmp.length() <= length) {
      final int insertLength = length - tmp.length();
      for (int pos = 0; pos < insertLength; pos++) {
        tmp.insert(0, "0");
      }
      tmpStr = tmp.toString();
    } else {
      tmpStr = tmp.substring(tmp.length() - length);
    }
    final byte[] b = ArchiveUtils.toAsciiBytes(tmpStr);
    out.write(b);
    count(b.length);
  }
  @Test
  public void testGettingToEhcacheConfiguration() {
    // tag::mutableConfigurationExample[]
    MutableConfiguration<Long, String> configuration = new MutableConfiguration<Long, String>();
    configuration.setTypes(Long.class, String.class);
    Cache<Long, String> cache = cacheManager.createCache("someCache", configuration); // <1>

    CompleteConfiguration<Long, String> completeConfiguration =
        cache.getConfiguration(CompleteConfiguration.class); // <2>

    Eh107Configuration<Long, String> eh107Configuration =
        cache.getConfiguration(Eh107Configuration.class); // <3>

    CacheRuntimeConfiguration<Long, String> runtimeConfiguration =
        eh107Configuration.unwrap(CacheRuntimeConfiguration.class); // <4>
    // end::mutableConfigurationExample[]
    assertThat(completeConfiguration, notNullValue());
    assertThat(runtimeConfiguration, notNullValue());

    // Check uses default JSR-107 expiry
    long nanoTime = System.nanoTime();
    LOGGER.info("Seeding random with {}", nanoTime);
    Random random = new Random(nanoTime);
    assertThat(
        runtimeConfiguration
            .getExpiry()
            .getExpiryForCreation(random.nextLong(), Long.toOctalString(random.nextLong())),
        equalTo(org.ehcache.expiry.Duration.FOREVER));
    assertThat(
        runtimeConfiguration
            .getExpiry()
            .getExpiryForAccess(random.nextLong(), Long.toOctalString(random.nextLong())),
        nullValue());
    assertThat(
        runtimeConfiguration
            .getExpiry()
            .getExpiryForUpdate(
                random.nextLong(),
                Long.toOctalString(random.nextLong()),
                Long.toOctalString(random.nextLong())),
        nullValue());
  }
Exemple #5
0
  /** converts the number l into a byte array */
  public static byte[] toId(long l) {
    String str = Long.toOctalString(l);

    if (str.length() % 2 != 0) {
      str = "0" + str;
    }

    byte[] result = new byte[str.length() / 2];
    StringBuffer number = new StringBuffer("xx");

    for (int i = 0; i < result.length; i++) {
      number.setCharAt(0, str.charAt(i * 2));
      number.setCharAt(1, str.charAt(i * 2 + 1));
      result[i] = Integer.valueOf(number.toString()).byteValue();

      if (result[i] == org.jacorb.poa.POAConstants.OBJECT_KEY_SEP_BYTE) {
        result[i] = (byte) 48; // char 0 , hex 30
      } else if (result[i] == org.jacorb.poa.POAConstants.MASK_BYTE) {
        result[i] = (byte) 19; // char !!, hex 13
      }
    }
    return result;
  }
Exemple #6
0
 public String format(long value, boolean unsigned) {
   return Long.toOctalString(value);
 }
 private StringTh CstrOct(
     String methodName, Thing[] args, Evaller evaller, Framelike frame, Syntax src)
     throws FisherException {
   checkNumberOfArgs(0, 0, methodName, args, evaller, frame, src);
   return StringTh.of(Long.toOctalString(value));
 }
Exemple #8
0
 public static String decToOctal(String dec) {
   if (isEmpty(dec)) return "0";
   return Long.toOctalString(Long.parseLong(dec));
 }
  /**
   * Method to go though the HDFS filesystem in a DFS to find all files
   *
   * <p>fs:FileSystem object from HDFS minDate: Oldest date for files to be backed up maxDate:Newest
   * date for files to be backed up p:Path in HDFS to look for files pathList:Will be filled with
   * all files in p hmTimestamps: hashmap of timestamps for later sorting
   */
  public void checkDir(
      FileSystem fs,
      long minDate,
      long maxDate,
      Path p,
      ArrayList<Path> pathList,
      HashMap<Path, Long> hmTimestamps) {
    long tmpDate;
    FileStatus[] fStat;

    try {
      String sPath = p.toUri().getPath();

      // If this is a directory
      if (fs.getFileStatus(p).isDir()) {
        // ignore certain directories
        if ("dfstmp".equals(p.getName())
            || "tmp".equals(p.getName())
            || "jobtracker".equals(p.getName())
            || sPath.startsWith("/mapred")
            || "ops".equals(p.getName())
            || p.getName().startsWith("_distcp_logs")) {
          return;
        }

        // dump the mkdir and chmod commands for this
        // directory -- skip root directory only
        {
          FileStatus stat = fs.getFileStatus(p);

          if (!sPath.equals("/")) {
            m_wrMkdirs.println("hadoop fs -mkdir " + sPath);
          }

          m_wrChmods.println(
              "hadoop fs -chown " + stat.getOwner() + ":" + stat.getGroup() + " " + sPath);

          Short sh = new Short(stat.getPermission().toShort());
          m_wrChmods.println(
              "hadoop fs -chmod " + Long.toOctalString(sh.longValue()) + " " + sPath);
        }

        fStat = fs.listStatus(p);

        // Do a recursive call to all elements
        for (int i = 0; i < fStat.length; i++) {
          checkDir(fs, minDate, maxDate, fStat[i].getPath(), pathList, hmTimestamps);
        }
      } else {
        // If not a directory then we've found a file

        // ignore crc files
        if (p.getName().endsWith(".crc")) {
          return;
        }

        // ignore other files
        if (sPath.startsWith("/user/oozie/etl/workflows/")) {
          return;
        }

        // try to get the table name from the path. There are
        // various types of tables, from those replicated from
        // another database to regular hive tables to
        // partitioned hive tables.  We use table names to
        // both exclude some from the backup, and for the rest
        // to dump out the schema and partition name.
        if (m_ignoreTables != null && m_ignoreTables.doIgnoreFile(sPath)) {
          m_nIgnoredTables++;

          if (m_nIgnoredTables < 5) {
            System.out.println("Skipping ignore-table file: " + sPath);
          } else if (m_nIgnoredTables == 5) {
            System.out.println("(...not showing other skipped tables...)");
          }
          return;
        }

        FileStatus stat = fs.getFileStatus(p);

        tmpDate = stat.getModificationTime() / 1000;

        // store the chmods/chowns for all files
        m_wrChmods.println(
            "hadoop fs -chown " + stat.getOwner() + ":" + stat.getGroup() + " " + sPath);

        m_wrChmods.println("hadoop fs -chmod " + stat.getPermission().toShort() + " " + sPath);

        // check dates.  is it too young?
        if (tmpDate < minDate) {
          return;
        }

        // is the file too recent?
        if (tmpDate > maxDate) {
          // System.out.println("file too recent: " + sPath);
          return;
        }

        // file timestamp is ok
        pathList.add(p);

        hmTimestamps.put(p, new Long(tmpDate));

        // store info about total bytes neeed to backup
        m_nTotalBytes += fs.getContentSummary(p).getLength();
      }
    } catch (IOException e) {
      System.err.println("ERROR: could not open " + p + ": " + e);

      // System.exit(1) ;
    }
  }
Exemple #10
0
  private String substitute(String spec, long n) throws IOException {
    boolean escaped = false;
    byte[] str = spec.getBytes();
    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < str.length; i++) {
      char c = (char) (str[i] & 0xFF);
      if (escaped) {
        sb.append(c);
        escaped = false;
      } else if (c == '\\') {
        if (i + 1 == str.length) throw new TextParseException("invalid escape character");
        escaped = true;
      } else if (c == '$') {
        boolean negative = false;
        long offset = 0;
        long width = 0;
        long base = 10;
        boolean wantUpperCase = false;
        if (i + 1 < str.length && str[i + 1] == '$') {
          // '$$' == literal '$' for backwards
          // compatibility with old versions of BIND.
          c = (char) (str[++i] & 0xFF);
          sb.append(c);
          continue;
        } else if (i + 1 < str.length && str[i + 1] == '{') {
          // It's a substitution with modifiers.
          i++;
          if (i + 1 < str.length && str[i + 1] == '-') {
            negative = true;
            i++;
          }
          while (i + 1 < str.length) {
            c = (char) (str[++i] & 0xFF);
            if (c == ',' || c == '}') break;
            if (c < '0' || c > '9') throw new TextParseException("invalid offset");
            c -= '0';
            offset *= 10;
            offset += c;
          }
          if (negative) offset = -offset;

          if (c == ',') {
            while (i + 1 < str.length) {
              c = (char) (str[++i] & 0xFF);
              if (c == ',' || c == '}') break;
              if (c < '0' || c > '9') throw new TextParseException("invalid width");
              c -= '0';
              width *= 10;
              width += c;
            }
          }

          if (c == ',') {
            if (i + 1 == str.length) throw new TextParseException("invalid base");
            c = (char) (str[++i] & 0xFF);
            if (c == 'o') base = 8;
            else if (c == 'x') base = 16;
            else if (c == 'X') {
              base = 16;
              wantUpperCase = true;
            } else if (c != 'd') throw new TextParseException("invalid base");
          }

          if (i + 1 == str.length || str[i + 1] != '}')
            throw new TextParseException("invalid modifiers");
          i++;
        }
        long v = n + offset;
        if (v < 0) throw new TextParseException("invalid offset expansion");
        String number;
        if (base == 8) number = Long.toOctalString(v);
        else if (base == 16) number = Long.toHexString(v);
        else number = Long.toString(v);
        if (wantUpperCase) number = number.toUpperCase();
        if (width != 0 && width > number.length()) {
          int zeros = (int) width - number.length();
          while (zeros-- > 0) sb.append('0');
        }
        sb.append(number);
      } else {
        sb.append(c);
      }
    }
    return sb.toString();
  }