Examples of ByteArray


Examples of org.pdfclown.util.ByteArray

                  itemIndex++
                  )
                {
                  // 1. Input code.
                  moveNext();
                  ByteArray inputCode = new ByteArray((byte[])token);
                  // 2. Character...
                  moveNext();
                  switch(tokenType)
                  {
                    case Hex: // ...code (hex).
                      codes.put(inputCode,ConvertUtils.byteArrayToInt((byte[])token));
                      break;
                    case Integer: // ...code (plain).
                      codes.put(inputCode,(Integer)token);
                      break;
                    case Name: // ...name.
                      codes.put(inputCode,GlyphMapping.nameToCode((String)token));
                      break;
                    default:
                      throw new RuntimeException(
                        operator + " section syntax error: hex string, integer or name expected instead of " + tokenType
                        );
                  }
                }
              }
              else if(operator.equals(BeginBaseFontRangeOperator)
                || operator.equals(BeginCIDRangeOperator))
              {
                /*
                  NOTE: The first and second elements in each line are the beginning and
                  ending valid input codes for the template font; the third element is
                  the beginning character code for the range.
                */
                for(
                  int itemIndex = 0;
                  itemIndex < itemCount;
                  itemIndex++
                  )
                {
                  // 1. Beginning input code.
                  moveNext();
                  byte[] beginInputCode = (byte[])token;
                  // 2. Ending input code.
                  moveNext();
                  byte[] endInputCode = (byte[])token;
                  // 3. Character codes.
                  moveNext();
                  switch(tokenType)
                  {
                    case Hex:
                    case Integer:
                    {
                      byte[] inputCode = beginInputCode;
                      int charCode;
                      switch(tokenType)
                      {
                        case Hex:
                          charCode = ConvertUtils.byteArrayToInt((byte[])token);
                          break;
                        case Integer:
                          charCode = (Integer)token;
                          break;
                        default:
                          throw new RuntimeException(
                            operator + " section syntax error: hex string or integer expected instead of " + tokenType
                            );
                      }
                      int endCharCode = charCode + (ConvertUtils.byteArrayToInt(endInputCode) - ConvertUtils.byteArrayToInt(beginInputCode));
                      while(true)
                      {
                        codes.put(new ByteArray(inputCode),charCode);
                        if(charCode == endCharCode)
                          break;

                        OperationUtils.increment(inputCode);
                        charCode++;
                      }
                      break;
                    }
                    case ArrayBegin:
                    {
                      byte[] inputCode = beginInputCode;
                      while(moveNext()
                        && tokenType != TokenTypeEnum.ArrayEnd)
                      {
                        codes.put(new ByteArray(inputCode),GlyphMapping.nameToCode((String)token));
                        OperationUtils.increment(inputCode);
                      }
                      break;
                    }
                    default:
View Full Code Here

Examples of org.pdfclown.util.ByteArray

          (i.e. when ToUnicode stream is available).
        */
        Map<Integer,Integer> unicodeGlyphIndexes = new Hashtable<Integer,Integer>();
        for(Map.Entry<Integer,Integer> glyphIndexEntry : glyphIndexes.entrySet())
        {
          Integer code = codes.get(new ByteArray(new byte[]{(byte)(int)glyphIndexEntry.getKey()}));
          if(code == null)
            continue;

          unicodeGlyphIndexes.put(code,glyphIndexEntry.getValue());
        }
        glyphIndexes = unicodeGlyphIndexes;
      }
    }

    PdfDataObject encodingObject = getBaseDataObject().resolve(PdfName.Encoding);
    EnumSet<FlagsEnum> flags = getFlags();
    if(flags.contains(FlagsEnum.Symbolic)
      || (!flags.contains(FlagsEnum.Nonsymbolic) && encodingObject == null)) // Symbolic.
    {
      symbolic = true;

      if(glyphIndexes == null)
      {
        /*
          NOTE: In case no font file is available, we have to synthesize its metrics
          from existing entries.
        */
        glyphIndexes = new Hashtable<Integer,Integer>();
        PdfArray glyphWidthObjects = (PdfArray)getBaseDataObject().resolve(PdfName.Widths);
        if(glyphWidthObjects != null)
        {
          int code = ((PdfInteger)getBaseDataObject().get(PdfName.FirstChar)).getRawValue();
          for(PdfDirectObject glyphWidthObject : glyphWidthObjects)
          {
            if(((PdfInteger)glyphWidthObject).getRawValue() > 0)
            {glyphIndexes.put(code,code);}

            code++;
          }
        }
      }

      if(codes == null)
      {
        Map<ByteArray,Integer> codes = new HashMap<ByteArray,Integer>();
        for(Map.Entry<Integer,Integer> glyphIndexEntry : glyphIndexes.entrySet())
        {
          if(glyphIndexEntry.getValue() > 0)
          {
            int glyphCharCode = glyphIndexEntry.getKey();
            byte[] charCode = new byte[]{(byte)glyphCharCode};
            codes.put(new ByteArray(charCode),glyphCharCode);
          }
        }
        this.codes = new BiMap<ByteArray,Integer>(codes);
      }
    }
    else // Nonsymbolic.
    {
      symbolic = false;

      if(codes == null)
      {
        Map<ByteArray,Integer> codes;
        if(encodingObject == null) // Default encoding.
        {codes = Encoding.get(PdfName.StandardEncoding).getCodes();}
        else if(encodingObject instanceof PdfName) // Predefined encoding.
        {codes = Encoding.get((PdfName)encodingObject).getCodes();}
        else // Custom encoding.
        {
          PdfDictionary encodingDictionary = (PdfDictionary)encodingObject;

          // 1. Base encoding.
          PdfName baseEncodingName = (PdfName)encodingDictionary.get(PdfName.BaseEncoding);
          if(baseEncodingName == null) // Default base encoding.
          {codes = Encoding.get(PdfName.StandardEncoding).getCodes();}
          else // Predefined base encoding.
          {codes = Encoding.get(baseEncodingName).getCodes();}

          // 2. Differences.
          loadEncodingDifferences(encodingDictionary, codes);
        }
        this.codes = new BiMap<ByteArray,Integer>(codes);
      }

      if(glyphIndexes == null)
      {
        /*
          NOTE: In case no font file is available, we have to synthesize its metrics
          from existing entries.
        */
        glyphIndexes = new Hashtable<Integer,Integer>();
        PdfArray glyphWidthObjects = (PdfArray)getBaseDataObject().resolve(PdfName.Widths);
        if(glyphWidthObjects != null)
        {
          ByteArray charCode = new ByteArray(
            new byte[]
            {(byte)(int)((PdfInteger)getBaseDataObject().get(PdfName.FirstChar)).getRawValue()}
            );
          for(PdfDirectObject glyphWidthObject : glyphWidthObjects)
          {
View Full Code Here

Examples of org.sdnplatform.sync.internal.util.ByteArray

    /**
     * Always uses UTF-8.
     */
    public static ByteArray toByteArray(String s) {
        try {
            return new ByteArray(s.getBytes("UTF-8"));
        } catch(UnsupportedEncodingException e) {
            /* Should not happen */
            throw new IllegalStateException(e);
        }
    }
View Full Code Here

Examples of org.sonar.duplications.block.ByteArray

      int endLine = unit.getEndLine();

      // TODO Godin: in fact we could work directly with id instead of key - this will allow to decrease memory consumption
      Block block = Block.builder()
        .setResourceId(resourceKey)
        .setBlockHash(new ByteArray(hash))
        .setIndexInFile(indexInFile)
        .setLines(startLine, endLine)
        .build();

      // Group blocks by hash
View Full Code Here

Examples of org.tc65sh.util.ByteArray

        File f = new File(filepath);
        FileInputStream in = new FileInputStream(f);
        byte[] buf = new byte[(int) f.length()];
        in.read(buf);
        in.close();
        ByteArray content = new ByteArray(buf);
        FileInfo fi = new FileInfo(false, f.getName(), (int) f.length(), new Date(f.lastModified()));
        FileHolder fh = new FileHolder(fi, content);
        return fh;
    }
View Full Code Here

Examples of org.xmlBlaster.util.xbformat.ByteArray

               Object o = p.getContent();
               if (o instanceof String) {
                  content = ((String)o).getBytes(Constants.UTF8_ENCODING);
               } else if (o instanceof InputStream) {
                  InputStream is = (InputStream) o;
                  ByteArray ba = new ByteArray(p.getSize() > 0 ? p.getSize() : 1024, is);
                  content = ba.toByteArray();
               } else {
                  content = (o.toString()).getBytes(Constants.UTF8_ENCODING);
               }
              
               if (p instanceof MimeBodyPart && Constants.EMAIL_TRANSFER_ENCODING.equals(((MimeBodyPart)p).getEncoding())) {
View Full Code Here

Examples of tv.porst.swfretools.parser.structures.ByteArray

    final UINT16 streamId = parseUINT16(parser, 0x00006, "VideoFrame::StreamId");
    final UINT16 frameNum = parseUINT16(parser, 0x00006, "VideoFrame::FrameNum");

    final int dataBytes = header.getNormalizedLength() - UINT16.BYTE_LENGTH - UINT16.BYTE_LENGTH;

    final ByteArray videoData = parseByteArray(parser, dataBytes < 0 ? 0 : dataBytes, 0x00006, "VideoFrame::VideoData");

    return new VideoFrameTag(header, streamId, frameNum, videoData);
  }
View Full Code Here

Examples of voldemort.utils.ByteArray

        fwriter.write(new StoreDefinitionsMapper().writeStoreList(newStores));
        fwriter.close();

        // check version
        String sysStoreName = SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name();
        ByteArray metadataKey = new ByteArray(ByteUtils.getBytes(MetadataVersionStoreUtils.VERSIONS_METADATA_KEY,
                                                                 "utf-8"));
        for(VoldemortServer vs: vservers.values()) {
            List<Versioned<byte[]>> result = vs.getStoreRepository()
                                               .getLocalStore(sysStoreName)
                                               .get(metadataKey, null);
View Full Code Here

Examples of voldemort.utils.ByteArray

                                                       OPERATION_TIMEOUT,
                                                       new VoldemortException());

        start = System.nanoTime();
        try {
            s1.put(new ByteArray("test".getBytes()), versioned, null);
        } finally {
            long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
            assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
        }
        // Putting extra key to test getAll
        s1.put(new ByteArray("test2".getBytes()), versioned, null);

        start = System.nanoTime();
        try {
            s1.get(new ByteArray("test".getBytes()), null);
        } finally {
            long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
            assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
        }

        start = System.nanoTime();
        try {
            List<Version> versions = s1.getVersions(new ByteArray("test".getBytes()));
            for(Version version: versions) {
                assertEquals(version.compare(versioned.getVersion()), Occurred.BEFORE);
            }
        } finally {
            long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
            assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
        }

        start = System.nanoTime();
        try {
            s1.delete(new ByteArray("test".getBytes()), versioned.getVersion());
        } finally {
            long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
            assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
        }

        // make sure sleepy stores processed the delete before checking,
        // otherwise, we might be bailing
        // out of the test too early for the delete to be processed.
        Thread.sleep(SLEEPY_TIME * 2);
        List<ByteArray> keys = Lists.newArrayList(new ByteArray("test".getBytes()),
                                                  new ByteArray("test2".getBytes()));

        Map<ByteArray, List<Versioned<byte[]>>> values = s1.getAll(keys, null);
        assertFalse("'test' did not get deleted.",
                    values.containsKey(new ByteArray("test".getBytes())));
        ByteUtils.compare(values.get(new ByteArray("test2".getBytes())).get(0).getValue(),
                          new byte[] { 1 });

        // Basic put with zone read = 1, zone write = 1
        Store<ByteArray, byte[], byte[]> s2 = getStore(cluster,
                                                       1,
                                                       1,
                                                       1,
                                                       1,
                                                       8,
                                                       null,
                                                       Sets.newHashSet(4, 5, 6, 7),
                                                       zoneReplicationFactor,
                                                       RoutingStrategyType.ZONE_STRATEGY,
                                                       SLEEPY_TIME,
                                                       BANNAGE_PERIOD,
                                                       new VoldemortException());

        start = System.nanoTime();

        try {
            s2.put(new ByteArray("test".getBytes()), versioned, null);
        } finally {
            long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
            assertTrue(elapsed + " > " + SLEEPY_TIME, elapsed >= SLEEPY_TIME);
        }
        s2.put(new ByteArray("test2".getBytes()), versioned, null);

        try {
            s2.get(new ByteArray("test".getBytes()), null);
            fail("Should have shown exception");
        } catch(InsufficientZoneResponsesException e) {
            /*
             * Why would you want responses from two zones and wait for only one
             * response...
             */
        }

        try {
            s2.getVersions(new ByteArray("test".getBytes()));
            fail("Should have shown exception");
        } catch(InsufficientZoneResponsesException e) {
            /*
             * Why would you want responses from two zones and wait for only one
             * response...
             */
        }

        try {
            s2.delete(new ByteArray("test".getBytes()), null);
        } catch(InsufficientZoneResponsesException e) {
            /*
             * Why would you want responses from two zones and wait for only one
             * response...
             */
        }

        values = s2.getAll(keys, null);
        assertFalse("'test' did not get deleted.",
                    values.containsKey(new ByteArray("test".getBytes())));
        ByteUtils.compare(values.get(new ByteArray("test2".getBytes())).get(0).getValue(),
                          new byte[] { 1 });

        // Basic put with zone read = 0, zone write = 0 and failures in other
        // dc, but should still work
        Store<ByteArray, byte[], byte[]> s3 = getStore(cluster,
                                                       1,
                                                       1,
                                                       0,
                                                       0,
                                                       8,
                                                       Sets.newHashSet(4, 5, 6, 7),
                                                       null,
                                                       zoneReplicationFactor,
                                                       RoutingStrategyType.ZONE_STRATEGY,
                                                       SLEEPY_TIME,
                                                       BANNAGE_PERIOD,
                                                       new VoldemortException());

        start = System.nanoTime();
        try {
            s3.put(new ByteArray("test".getBytes()), versioned, null);
        } finally {
            long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
            assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
        }
        // Putting extra key to test getAll
        s3.put(new ByteArray("test2".getBytes()), versioned, null);

        start = System.nanoTime();
        try {
            List<Version> versions = s3.getVersions(new ByteArray("test".getBytes()));
            for(Version version: versions) {
                assertEquals(version.compare(versioned.getVersion()), Occurred.BEFORE);
            }
        } finally {
            long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
            assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
        }

        start = System.nanoTime();
        try {
            s3.get(new ByteArray("test".getBytes()), null);
        } finally {
            long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
            assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
        }

        start = System.nanoTime();
        try {
            s3.delete(new ByteArray("test".getBytes()), versioned.getVersion());
        } finally {
            long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
            assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
        }

        // Basic put with zone read = 1, zone write = 1 and failures in other
        // dc, should not work
        Store<ByteArray, byte[], byte[]> s4 = getStore(cluster,
                                                       2,
                                                       2,
                                                       1,
                                                       1,
                                                       8,
                                                       Sets.newHashSet(4, 5, 6, 7),
                                                       null,
                                                       zoneReplicationFactor,
                                                       RoutingStrategyType.ZONE_STRATEGY,
                                                       SLEEPY_TIME,
                                                       BANNAGE_PERIOD,
                                                       new VoldemortException());

        try {
            s4.put(new ByteArray("test".getBytes()), new Versioned<byte[]>(new byte[] { 1 }), null);
            fail("Should have shown exception");
        } catch(InsufficientZoneResponsesException e) {
            /*
             * The other zone is down and you expect a result from both zones
             */
        }

        try {
            s4.getVersions(new ByteArray("test".getBytes()));
            fail("Should have shown exception");
        } catch(InsufficientZoneResponsesException e) {
            /*
             * The other zone is down and you expect a result from both zones
             */
        }

        try {
            s4.get(new ByteArray("test".getBytes()), null);
            fail("Should have shown exception");
        } catch(InsufficientZoneResponsesException e) {
            /*
             * The other zone is down and you expect a result from both zones
             */
        }

        try {
            s4.delete(new ByteArray("test".getBytes()), versioned.getVersion());
            fail("Should have shown exception");
        } catch(InsufficientZoneResponsesException e) {
            /*
             * The other zone is down and you expect a result from both zones
             */
 
View Full Code Here

Examples of voldemort.utils.ByteArray

    }

    @Test
    public void testGetVersions2() throws Exception {
        List<ByteArray> keys = getKeys(2);
        ByteArray key = keys.get(0);
        byte[] value = getValue();
        Store<ByteArray, byte[], byte[]> store = getStore();
        store.put(key, Versioned.value(value), null);
        List<Versioned<byte[]>> versioneds = store.get(key, null);
        List<Version> versions = store.getVersions(key);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.