[gatein-commits] gatein SVN: r2022 - in portal/trunk/component: portal/src/main/java/org/exoplatform/portal/resource and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Sun Mar 7 10:28:04 EST 2010


Author: julien_viet
Date: 2010-03-07 10:28:04 -0500 (Sun, 07 Mar 2010)
New Revision: 2022

Added:
   portal/trunk/component/common/src/main/java/org/exoplatform/commons/utils/ByteArrayOutput.java
   portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CachedStylesheet.java
Log:
fixing what I broke


Added: portal/trunk/component/common/src/main/java/org/exoplatform/commons/utils/ByteArrayOutput.java
===================================================================
--- portal/trunk/component/common/src/main/java/org/exoplatform/commons/utils/ByteArrayOutput.java	                        (rev 0)
+++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/utils/ByteArrayOutput.java	2010-03-07 15:28:04 UTC (rev 2022)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.commons.utils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class ByteArrayOutput implements BinaryOutput {
+
+   /** . */
+   private static final Charset UTF_8 = Charset.forName("UTF-8");
+
+   /** . */
+   private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+   public Charset getCharset()
+   {
+      return UTF_8;
+   }
+
+   public void write(byte b) throws IOException
+   {
+      baos.write(b);
+   }
+
+   public void write(byte[] bytes) throws IOException
+   {
+      baos.write(bytes);
+   }
+
+   public void write(byte[] bytes, int off, int len) throws IOException
+   {
+      baos.write(bytes, off, len);
+   }
+
+   public byte[] getBytes()
+   {
+      return baos.toByteArray();
+   }
+
+   public String getString() throws UnsupportedEncodingException
+   {
+      return baos.toString(UTF_8.name());
+   }
+}

Added: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CachedStylesheet.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CachedStylesheet.java	                        (rev 0)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CachedStylesheet.java	2010-03-07 15:28:04 UTC (rev 2022)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.resource;
+
+import org.exoplatform.commons.utils.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.reflect.UndeclaredThrowableException;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class CachedStylesheet
+{
+
+   /** The optimized encoder. */
+   private static final TextEncoder encoder = new CharsetTextEncoder(new TableCharEncoder(CharsetCharEncoder.getUTF8()));
+
+   /** . */
+   private final String text;
+
+   /** . */
+   private final byte[] bytes;
+
+   public CachedStylesheet(String text)
+   {
+      // Compute encoded bytes
+      byte[] bytes;
+      try
+      {
+         ByteArrayOutputStream baos = new ByteArrayOutputStream(text.length() * 2);
+         encoder.encode(text, 0, text.length(), baos);
+         baos.flush();
+         bytes = baos.toByteArray();
+      } catch (IOException e)
+      {
+         throw new UndeclaredThrowableException(e, "That should not happen");
+      }
+
+      //
+      this.text = text;
+      this.bytes = bytes;
+   }
+
+   public String getText()
+   {
+      return text;
+   }
+
+   public void writeTo(BinaryOutput output) throws IOException
+   {
+      output.write(bytes);
+   }
+}



More information about the gatein-commits mailing list