Package java.io

Examples of java.io.ByteArrayOutputStream


public class CacheMarshaller300Test
{
   public void testArrayTypes() throws Exception
   {
      Marshaller m = new CacheMarshaller300();
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(bout);
      byte[] s = {1, 2, 3, 4};
      m.objectToObjectStream(s, out);
      out.close();

      ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
      ObjectInputStream ois = new ObjectInputStream(bin);

      Object o = m.objectFromObjectStream(ois);

      ois.close();
View Full Code Here


   }

   public void testBoxedArrayTypes() throws Exception
   {
      Marshaller m = new CacheMarshaller300();
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(bout);
      Byte[] s = new Byte[]{1, 2, 3, 4};
      m.objectToObjectStream(s, out);
      out.close();

      ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
      ObjectInputStream ois = new ObjectInputStream(bin);

      Object o = m.objectFromObjectStream(ois);

      ois.close();
View Full Code Here

   }

   public void testMixedArrayTypes() throws Exception
   {
      Marshaller m = new CacheMarshaller300();
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(bout);
      Object[] s = {"Hello", Fqn.fromString("/a"), 1, null};
      m.objectToObjectStream(s, out);
      out.close();

      ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
      ObjectInputStream ois = new ObjectInputStream(bin);

      Object o = m.objectFromObjectStream(ois);

      ois.close();
View Full Code Here

    /**
     * method to get the byte array representing the command
     */
    public byte[] getBytes() throws IOException {
       
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
       
        if (data == null) {
            // put command specific data in the outputstream
            writeCommandData(baos);
        
            // add the TLVs to the outputstream  
            if (tlvList != null && !tlvList.isEmpty()) {
                for (Iterator iter = tlvList.iterator(); iter.hasNext();) {
                    baos.write( ((TLV)iter.next()).getBytes() );                   
                }
            }
            data = baos.toByteArray();
        }
       
        ByteArrayOutputStream cmdOS = new ByteArrayOutputStream();
        int cmdDataLen = 0;
        if (snacPacket != null) {
            cmdDataLen += SNACPacket.SNACPACKET_LENGTH;
        }
        if (data != null) {
            cmdDataLen += data.length;
        }
       
        // set the flap header length
        flapHdr.setDataLength(cmdDataLen);
       
        cmdOS.write( flapHdr.getBytes() );
        if (snacPacket != null) {
            cmdOS.write(snacPacket.getBytes());
        }
        cmdOS.write(data, 0, data.length);
        byte[] cmdBytes = cmdOS.toByteArray();
        return cmdBytes;
    }
View Full Code Here

        byte[] tlvBytes = null;

        if (tlvList != null && !tlvList.isEmpty()) {

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
           
            try {
                for (Iterator iter = tlvList.iterator(); iter.hasNext();) {

                    baos.write(((TLV) iter.next()).getBytes());
                }
            } catch (IOException e) {
                //e.printStackTrace();
            }
           
            tlvBytes = baos.toByteArray();
        }

        return tlvBytes;
    }
View Full Code Here

    * Useful when {@link testEqualityOnTransformedFiles} fails and you need to isolate a failure.
    */
   public void testSingleFile() throws Exception
   {
      String fileName = getFileName("/policyPerRegion-eviction.xml");
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      convertor.parse(fileName, baos, XSLT_FILE);

      XmlConfigurationParser newParser = new XmlConfigurationParser();
      XmlConfigurationParser2x oldParser = new XmlConfigurationParser2x();

      Configuration newConfig = newParser.parseStream(new ByteArrayInputStream(baos.toByteArray()));
      Configuration oldConfig = oldParser.parseFile(fileName);

      assert oldConfig.equals(newConfig);
   }
View Full Code Here

            "total-replication-cache.xml",
      };
      for (String file : fileNames)
      {
         String fileName = getFileName(file);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         convertor.parse(fileName, baos, XSLT_FILE);

         XmlConfigurationParser newParser = new XmlConfigurationParser();
         XmlConfigurationParser2x oldParser = new XmlConfigurationParser2x();

         Configuration newConfig = newParser.parseStream(new ByteArrayInputStream(baos.toByteArray()));
         Configuration oldConfig = oldParser.parseFile(fileName);

         assert newConfig.equals(oldConfig);
      }
   }
View Full Code Here

            "policyPerRegion-eviction.xml",
      };
      for (String file : fileNames)
      {
         String fileName = getFileName(file);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         convertor.parse(fileName, baos, XSLT_FILE);

         XmlConfigurationParser newParser = new XmlConfigurationParser();
         XmlConfigurationParser2x oldParser = new XmlConfigurationParser2x();

         Configuration newConfig = newParser.parseStream(new ByteArrayInputStream(baos.toByteArray()));
         Configuration oldConfig = oldParser.parseFile(fileName);

         assert newConfig.equals(oldConfig);
      }
   }
View Full Code Here

   public void testUnlimitedValues() throws Exception
   {
      // in 3.x, unlimited values in eviction are denoted by -1 and not 0!
      String fileName = getFileName("/zeroTTL.xml");
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      convertor.parse(fileName, baos, XSLT_FILE);

      XmlConfigurationParser newParser = new XmlConfigurationParser();
      XmlConfigurationParser2x oldParser = new XmlConfigurationParser2x();

      Configuration newConfig = newParser.parseStream(new ByteArrayInputStream(baos.toByteArray()));
      Configuration oldConfig = oldParser.parseFile(fileName);

      for (EvictionRegionConfig erc : oldConfig.getEvictionConfig().getEvictionRegionConfigs())
      {
         correctUnlimitedValues(erc);
View Full Code Here

      oldImpl.put(Fqn.fromString("/a/b/d"), "key2", "value2");
      oldImpl.put(Fqn.fromString("/a/b/e"), "key3", "value3");
      oldImpl.put(Fqn.fromString("/a/f/e"), "key4", "value4");
      oldImpl.put(Fqn.ROOT, "root_key", "root_value");

      ByteArrayOutputStream newBaos = new ByteArrayOutputStream(1024);
      MarshalledValueOutputStream newOs = new MarshalledValueOutputStream(newBaos);
      newImpl.start();
      newImpl.loadEntireState(newOs);
      newImpl.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, newOs);
      newOs.close();
      newImpl.remove(Fqn.ROOT);
      assertNull(newImpl.get(Fqn.fromString("/a/b/c")));
      assertNull(newImpl.get(Fqn.fromString("/a/b/d")));
      assertNull(newImpl.get(Fqn.fromString("/a/b/e")));
      assertNull(newImpl.get(Fqn.fromString("/a/f/e")));
      assertNull(newImpl.get(Fqn.ROOT));
      ByteArrayInputStream bais = new ByteArrayInputStream(newBaos.toByteArray());
      MarshalledValueInputStream is = new MarshalledValueInputStream(bais);
      newImpl.storeEntireState(is);
      assertEquals(newImpl.get(Fqn.fromString("/a/b/c")).get("key1"), "value1");
      assertEquals(newImpl.get(Fqn.fromString("/a/b/d")).get("key2"), "value2");
      assertEquals(newImpl.get(Fqn.fromString("/a/b/e")).get("key3"), "value3");
View Full Code Here

TOP

Related Classes of java.io.ByteArrayOutputStream

Copyright © 2018 www.massapicom. 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.