protected FixedTemplate(Object object, FixedDataSchema schema) throws TemplateOutputCastException
  {
    Class<?> objectClass = object.getClass();
    if (objectClass == String.class)
    {
      String data = (String) object;
      if (data.length() != schema.getSize())
      {
       throw new TemplateOutputCastException("Fixed size is " + schema.getSize() + ", string length is " + data.length());
      }
      _schema = schema;
      _data = ByteString.copyAvroString(data, true);
      if (_data == null)
      {
        throw new TemplateOutputCastException("String is not a valid representation of bytes");
      }
    }
    else if (objectClass == ByteString.class)
    {
      ByteString bytes = (ByteString) object;
      if (bytes.length() != schema.getSize())
      {
        throw new TemplateOutputCastException("Fixed size is " + schema.getSize() + ", ByteString length is " + bytes.length());
      }
      _schema = schema;
      _data = bytes;
    }
    else
    {
      throw new TemplateOutputCastException("Fixed input " + object + " is not a string or ByteString");
    }
  }
@Test
  public void testFixedTemplate()
  {
    String goodObjects[] = {
        "12345",
        "ABCDF"
    };

    ByteString goodByteStrings[] = {
        ByteString.copyAvroString("qwert", false)
    };

    Object badObjects[] = {
        "", "1", "12", "123", "1234", "1234\u0100", "123456",
        1, 2.0f, 3.0, 4L, new DataMap(), new DataList()
    };

    ByteString badByteStrings[]  = {
        ByteString.copyAvroString("", false),
        ByteString.copyAvroString("a", false),
        ByteString.copyAvroString("ab", false),
        ByteString.copyAvroString("abc", false),
        ByteString.copyAvroString("abcd", false),
        ByteString.copyAvroString("abcdef", false)
    };

    Integer lastHashCode = null;
    ByteString lastByteString = null;
    for (String o : goodObjects)
    {
      Exception exc = null;
      Fixed5 fixed = null;
      try
      {
        fixed = new Fixed5(o);
      }
      catch (Exception e)
      {
        exc = e;
      }
      assertNull(exc);

      // equals
      ByteString expectedByteString = ByteString.copyAvroString(o, false);
      assertEquals(fixed.data(), expectedByteString);
      assertTrue(fixed.equals(new Fixed5(expectedByteString)));
      if (lastByteString != null)
      {
        assertFalse(fixed.equals(lastByteString));
      }
      assertFalse(fixed.equals(null));
      assertFalse(fixed.equals(new Object()));

      // hashCode
      int newHashCode = fixed.hashCode();
      if (lastHashCode != null)
      {
        assertTrue(newHashCode != lastHashCode);
      }

      // toString
      assertEquals(expectedByteString.toString(), fixed.toString());

      lastHashCode = newHashCode;
      lastByteString = expectedByteString;

      // clone and copy
      testCopiers(fixed);
    }

    for (ByteString o : goodByteStrings)
    {
      Exception exc = null;
      Fixed5 fixed = null;
      try
      {
        fixed = new Fixed5(o);
      }
      catch (Exception e)
      {
        exc = e;
      }
      assertNull(exc);

      // equals
      assertEquals(fixed.data(), o);
      assertTrue(fixed.equals(new Fixed5(o)));
      if (lastByteString != null)
      {
        assertFalse(fixed.equals(lastByteString));
      }
      assertFalse(fixed.equals(null));
      assertFalse(fixed.equals(new Object()));

      // hashCode
      int newHashCode = fixed.hashCode();
      if (lastHashCode != null)
      {
        assertTrue(newHashCode != lastHashCode);
      }

      // toString
      assertEquals(o.toString(), fixed.toString());

      lastHashCode = newHashCode;
      lastByteString = o;

      // clone and copy
      testCopiers(fixed);
    }

    for (Object o : badObjects)
    {
      Exception exc = null;
      try
      {
        new Fixed5(o);
      }
      catch (Exception e)
      {
        exc = e;
      }
      assertTrue(exc != null);
      assertTrue(exc instanceof TemplateOutputCastException);
    }

    for (ByteString o : badByteStrings)
    {
      Exception exc = null;
      try
      {
        new Fixed5(o);
      }
      catch (Exception e)
      {
        exc = e;
      }
      assertTrue(exc != null);
      assertTrue(exc instanceof TemplateOutputCastException);
    }
  }