ArrayEncodedValueAdaptor.java revision 6eae34831fee1f116f3a453bdc5e143d68e05e03
1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/* 2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) * [The "BSD licence"] 3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) * Copyright (c) 2010 Ben Gruver (JesusFreke) 4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) * All rights reserved. 5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) * 6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without 703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * modification, are permitted provided that the following conditions 8f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * are met: 96e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 10f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 1103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 12f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 13f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * documentation and/or other materials provided with the distribution. 14f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * 3. The name of the author may not be used to endorse or promote products 15f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * derived from this software without specific prior written permission. 166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) * 176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) */ 2803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 2903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)package org.jf.baksmali.Adaptors.EncodedValue; 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 3103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)import org.jf.baksmali.IndentingPrintWriter; 3203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)import org.jf.dexlib.EncodedValue.EncodedValue; 336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)import org.jf.dexlib.EncodedValue.ArrayEncodedValue; 346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)import java.io.IOException; 366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)public class ArrayEncodedValueAdaptor { 386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) public static void writeTo(IndentingPrintWriter writer, ArrayEncodedValue encodedArray) throws IOException { 396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) writer.print('{'); 4003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) EncodedValue[] values = encodedArray.values; 4103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (values == null || values.length == 0) { 4203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) writer.print('}'); 4303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return; 44f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) writer.println(); 476d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) writer.indent(4); 486d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) boolean first = true; 496d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) for (EncodedValue encodedValue: encodedArray.values) { 50f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (!first) { 515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) writer.println(','); 525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 53f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) first = false; 54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 55f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) EncodedValueAdaptor.writeTo(writer, encodedValue); 56f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 57f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) writer.deindent(4); 58f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) writer.println(); 59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) writer.print('}'); 606d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) } 61f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)} 62f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)