Wednesday, December 21, 2011

Checkout a specific revision from subversion from command line


svn checkout svn://somepath@1234 working-directory
or
svn checkout url://repository/path@1234
or
svn checkout -r 1234 url://repository/path

Friday, December 9, 2011

UTF8 encode decode


/* Licensed to the Apache Software Foundation (ASF) under one or more
         * contributor license agreements.  See the NOTICE file distributed with
         * this work for additional information regarding copyright ownership.
         * The ASF licenses this file to You under the Apache License, Version 2.0
         * (the "License"); you may not use this file except in compliance with
         * the License.  You may obtain a copy of the License at
         *
         *     http://www.apache.org/licenses/LICENSE-2.0
         *
         * Unless required by applicable law or agreed to in writing, software
         * distributed under the License is distributed on an "AS IS" BASIS,
         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         * See the License for the specific language governing permissions and
         * limitations under the License.
         */

        package org.apache.harmony.nio_char.tests.java.nio.charset;

        import dalvik.annotation.TestTargetClass;
        import dalvik.annotation.TestTargets;
        import dalvik.annotation.TestTargetNew;
        import dalvik.annotation.TestLevel;

        import java.io.IOException;
        import java.nio.BufferOverflowException;
        import java.nio.ByteBuffer;
        import java.nio.CharBuffer;
        import java.nio.charset.Charset;
        import java.nio.charset.CharsetDecoder;
        import java.nio.charset.CharsetEncoder;
        import java.nio.charset.CoderMalfunctionError;
        import java.nio.charset.CoderResult;

        import junit.framework.TestCase;

        @TestTargetClass(CharsetEncoder.class)
        public class CharsetEncoderTest extends TestCase {

            /**
             * @tests java.nio.charset.CharsetEncoder.CharsetEncoder(
             *        java.nio.charset.Charset, float, float)
             */
            @TestTargets({@TestTargetNew(level=TestLevel.PARTIAL_COMPLETE,notes="Checks IllegalArgumentException",method="CharsetEncoder",args={java.nio.charset.Charset.class,float.class,float.class}),@TestTargetNew(level=TestLevel.PARTIAL_COMPLETE,notes="Checks IllegalArgumentException",method="CharsetEncoder",args={java.nio.charset.Charset.class,float.class,float.class,byte[].class})})
            public void test_ConstructorLjava_nio_charset_CharsetFF() {
                // Regression for HARMONY-141
                try {
                    Charset cs = Charset.forName("UTF-8");
                    new MockCharsetEncoderForHarmony141(cs, 1.1f, 1);
                    fail("Assert 0: Should throw IllegalArgumentException.");
                } catch (IllegalArgumentException e) {
                    // expected
                }

                try {
                    Charset cs = Charset.forName("ISO8859-1");
                    new MockCharsetEncoderForHarmony141(cs, 1.1f, 1,
                            new byte[] { 0x1a });
                    fail("Assert 1: Should throw IllegalArgumentException.");
                } catch (IllegalArgumentException e) {
                    // expected
                }
            }

            /**
             * @tests java.nio.charset.CharsetEncoder.CharsetEncoder(
             *        java.nio.charset.Charset, float, float)
             */
            @TestTargetNew(level=TestLevel.PARTIAL_COMPLETE,notes="",method="CharsetEncoder",args={java.nio.charset.Charset.class,float.class,float.class})
            public void test_ConstructorLjava_nio_charset_CharsetNull() {
                // Regression for HARMONY-491
                CharsetEncoder ech = new MockCharsetEncoderForHarmony491(null,
                        1, 1);
                assertNull(ech.charset());
            }

            /**
             * Helper for constructor tests
             */

            public static class MockCharsetEncoderForHarmony141 extends
                    CharsetEncoder {

                protected MockCharsetEncoderForHarmony141(Charset cs,
                        float averageBytesPerChar, float maxBytesPerChar) {
                    super (cs, averageBytesPerChar, maxBytesPerChar);
                }

                public MockCharsetEncoderForHarmony141(Charset cs,
                        float averageBytesPerChar, float maxBytesPerChar,
                        byte[] replacement) {
                    super (cs, averageBytesPerChar, maxBytesPerChar, replacement);
                }

                protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
                    return null;
                }
            }

            public static class MockCharsetEncoderForHarmony491 extends
                    CharsetEncoder {

                public MockCharsetEncoderForHarmony491(Charset arg0,
                        float arg1, float arg2) {
                    super (arg0, arg1, arg2);
                }

                protected CoderResult encodeLoop(CharBuffer arg0,
                        ByteBuffer arg1) {
                    return null;
                }

                public boolean isLegalReplacement(byte[] arg0) {
                    return true;
                }
            }

            /*
             * Test malfunction encode(CharBuffer)
             */
            @TestTargetNew(level=TestLevel.PARTIAL,notes="Regression test checks CoderMalfunctionError",method="encode",args={java.nio.CharBuffer.class})
            public void test_EncodeLjava_nio_CharBuffer() throws Exception {
                MockMalfunctionCharset cs = new MockMalfunctionCharset("mock",
                        null);
                try {
                    cs.encode(CharBuffer.wrap("AB"));
                    fail("should throw CoderMalfunctionError");
                } catch (CoderMalfunctionError e) {
                    // expected
                }
            }

            /*
             * Mock charset class with malfunction decode & encode.
             */
            static final class MockMalfunctionCharset extends Charset {

                public MockMalfunctionCharset(String canonicalName,
                        String[] aliases) {
                    super (canonicalName, aliases);
                }

                public boolean contains(Charset cs) {
                    return false;
                }

                public CharsetDecoder newDecoder() {
                    return Charset.forName("UTF-8").newDecoder();
                }

                public CharsetEncoder newEncoder() {
                    return new MockMalfunctionEncoder(this );
                }
            }

            /*
             * Mock encoder. encodeLoop always throws unexpected exception.
             */
            static class MockMalfunctionEncoder extends
                    java.nio.charset.CharsetEncoder {

                public MockMalfunctionEncoder(Charset cs) {
                    super (cs, 1, 3, new byte[] { (byte) '?' });
                }

                protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
                    throw new BufferOverflowException();
                }
            }

            /*
             * Test reserve bytes encode(CharBuffer,ByteBuffer,boolean)
             */
            @TestTargetNew(level=TestLevel.PARTIAL,notes="Functional test.",method="encode",args={java.nio.CharBuffer.class,java.nio.ByteBuffer.class,boolean.class})
            public void test_EncodeLjava_nio_CharBufferLjava_nio_ByteBufferB() {
                CharsetEncoder encoder = Charset.forName("utf-8").newEncoder();
                CharBuffer in1 = CharBuffer.wrap("\ud800");
                CharBuffer in2 = CharBuffer.wrap("\udc00");
                ByteBuffer out = ByteBuffer.allocate(4);
                encoder.reset();
                CoderResult result = encoder.encode(in1, out, false);
                assertEquals(4, out.remaining());
                assertTrue(result.isUnderflow());
                result = encoder.encode(in2, out, true);
                assertEquals(4, out.remaining());
                assertTrue(result.isMalformed());
            }

            /**
             * @tests {@link java.nio.charset.Charset#encode(java.nio.CharBuffer)
             */
            public void testUtf8Encoding() throws IOException {
                byte[] orig = new byte[] { (byte) 0xed, (byte) 0xa0,
                        (byte) 0x80 };
                String s = new String(orig, "UTF-8");
                assertEquals(1, s.length());
                assertEquals(55296, s.charAt(0));
                Charset.forName("UTF-8").encode(CharBuffer.wrap(s));
                //        ByteBuffer buf = <result>
                //        for (byte o : orig) {
                //            byte b = 0;
                //            buf.get(b);
                //            assertEquals(o, b);
                //        }
            }
        }


http://www.java2s.com/Open-Source/Android/android-core/platform-libcore/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java.htm


source : 

Sunday, November 20, 2011

creating header and footer for a existing pdf with iText


import java.awt.Color;
import java.io.FileOutputStream;

import com.itextpdf.text.Anchor;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfWriter;

public class PDF {

/**
* @param args
*/
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream("/home/zana/Desktop/v59-10.pdf"));

document.open();

PdfContentByte cb = writer.getDirectContent();

// Load existing PDF
PdfReader reader = new PdfReader(new PdfReader(
"/home/zana/Desktop/v59-9.pdf"));
PdfImportedPage page = writer.getImportedPage(reader, 1);

// Copy first page of existing PDF into output PDF
document.newPage();
cb.addTemplate(page, 0, 0);

// Add your new data / text here
// for example...
Font font = new Font();
font.setColor(BaseColor.BLUE);
font.setStyle(Font.UNDERLINE);
Paragraph paragraph = new Paragraph();
paragraph.setLeading(0, 25);
paragraph.setAlignment(Paragraph.ALIGN_LEFT);
paragraph.setAlignment(Paragraph.ALIGN_BASELINE);
Chunk chunk = new Chunk("http://www.geek-tutorials.com", font)
.setAnchor("http://www.geek-tutorials.com");
paragraph.add(chunk);
document.add(paragraph);

document.close();
} catch (Exception e) {
e.printStackTrace();
}
}

}

Tuesday, November 15, 2011

Turkish company builds 65-inch Android 'tablet' with Honeycomb, 1080p support (video)



Want Honeycomb on your TV? You can take your chances with a Google TV-enabled set from Sony, or you can get the full Android experience by adding a connected tablet to your HD mix -- if Istanbul-based Ardic gets its solution out the door, at least. The Turkish company's prototype uses a 10-inch Android Honeycomb-based tablet to power a 65-inch LCD with 1080p support for basic gestures, like pinch and zoom. The display currently has two touch sensors, but a version with four sensors is on the way, which will bring multi-touch support. The tablet is powered by an NVIDIA Tegra 2 SoC, and includes 1GB of RAM, 16GB of flash memory, dual cameras, HDMI, USB, microSD and 3G and WiFi connectivity. A dock enables instant connectivity with the OEM TV, including HDMI for video and audio, and USB for touch input (a wireless version is in the works as well).

The devs customized Android to support 1080p output, and it appears to work quite seamlessly, as you'll see in the embedded video. And this isn't simply another goofy demo or proof of concept -- the Turkish company is in talks with education and enterprise customers and hopes to bring this setup to production as a more power- and cost-efficient smart board alternative. The company eventually hopes to offer displays in a variety of sizes, that will all be powered by a pocketable device, such as a smartphone, but watch in wonder as the 65-inch proto we have today struts its stuff in the video after the break.

source : http://www.engadget.com/2011/11/14/turkish-company-builds-65-inch-android-tablet-with-honeycomb/