| | ,code,repo_name,path,language,license,size |
| | 0," |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #ifndef __MCU_STM32L0_BSP_H_ |
| | #define __MCU_STM32L0_BSP_H_ |
| |
|
| | #include <hal/hal_gpio.h> |
| | #include <stdint.h> |
| |
|
| | #ifdef __cplusplus |
| | extern ""C"" { |
| | #endif |
| |
|
| | |
| | |
| | |
| | struct stm32_uart_cfg { |
| | USART_TypeDef *suc_uart; |
| | volatile uint32_t *suc_rcc_reg; |
| | uint32_t suc_rcc_dev; |
| | int8_t suc_pin_tx; |
| | int8_t suc_pin_rx; |
| | int8_t suc_pin_rts; |
| | int8_t suc_pin_cts; |
| | uint8_t suc_pin_af; |
| | IRQn_Type suc_irqn; |
| | }; |
| |
|
| | |
| | |
| | |
| | int hal_gpio_init_af(int pin, uint8_t af_type, enum hal_gpio_pull pull, uint8_t |
| | od); |
| |
|
| | struct hal_flash; |
| | extern struct hal_flash stm32l0_flash_dev; |
| |
|
| | #ifdef __cplusplus |
| | } |
| | #endif |
| |
|
| | #endif |
| | ",mlaz/mynewt-core,hw/mcu/stm/stm32l0xx/include/mcu/stm32l0_bsp.h,C,apache-2.0,1735 |
| | 1,"package com.hazelcast.simulator.worker.metronome; |
| |
|
| | import java.util.concurrent.TimeUnit; |
| |
|
| | public class BusySpinningMetronomeTest extends AbstractMetronomeTest { |
| |
|
| | @Override |
| | public Metronome createMetronome(long interval, TimeUnit unit) { |
| | return new BusySpinningMetronome(unit.toNanos(interval),true); |
| | } |
| |
|
| | } |
| | ",jerrinot/hazelcast-stabilizer,simulator/src/test/java/com/hazelcast/simulator/worker/metronome/BusySpinningMetronomeTest.java,Java,apache-2.0,325 |
| | 2,"#!/usr/bin/env python |
| |
|
| | from tests.unit import unittest |
| | from tests.unit import AWSMockServiceTestCase |
| |
|
| | import mock |
| |
|
| | from boto.ec2.connection import EC2Connection |
| |
|
| | DESCRIBE_INSTANCE_VPC = r""""""<?xml version=""1.0"" encoding=""UTF-8""?> |
| | <DescribeInstancesResponse xmlns=""http: |
| | <requestId>c6132c74-b524-4884-87f5-0f4bde4a9760</requestId> |
| | <reservationSet> |
| | <item> |
| | <reservationId>r-72ef4a0a</reservationId> |
| | <ownerId>184906166255</ownerId> |
| | <groupSet/> |
| | <instancesSet> |
| | <item> |
| | <instanceId>i-instance</instanceId> |
| | <imageId>ami-1624987f</imageId> |
| | <instanceState> |
| | <code>16</code> |
| | <name>running</name> |
| | </instanceState> |
| | <privateDnsName/> |
| | <dnsName/> |
| | <reason/> |
| | <keyName>mykeypair</keyName> |
| | <amiLaunchIndex>0</amiLaunchIndex> |
| | <productCodes/> |
| | <instanceType>m1.small</instanceType> |
| | <launchTime>2012-12-14T23:48:37.000Z</launchTime> |
| | <placement> |
| | <availabilityZone>us-east-1d</availabilityZone> |
| | <groupName/> |
| | <tenancy>default</tenancy> |
| | </placement> |
| | <kernelId>aki-88aa75e1</kernelId> |
| | <monitoring> |
| | <state>disabled</state> |
| | </monitoring> |
| | <subnetId>subnet-0dc60667</subnetId> |
| | <vpcId>vpc-id</vpcId> |
| | <privateIpAddress>10.0.0.67</privateIpAddress> |
| | <sourceDestCheck>true</sourceDestCheck> |
| | <groupSet> |
| | <item> |
| | <groupId>sg-id</groupId> |
| | <groupName>WebServerSG</groupName> |
| | </item> |
| | </groupSet> |
| | <architecture>x86_64</architecture> |
| | <rootDeviceType>ebs</rootDeviceType> |
| | <rootDeviceName>/dev/sda1</rootDeviceName> |
| | <blockDeviceMapping> |
| | <item> |
| | <deviceName>/dev/sda1</deviceName> |
| | <ebs> |
| | <volumeId>vol-id</volumeId> |
| | <status>attached</status> |
| | <attachTime>2012-12-14T23:48:43.000Z</attachTime> |
| | <deleteOnTermination>true</deleteOnTermination> |
| | </ebs> |
| | </item> |
| | </blockDeviceMapping> |
| | <virtualizationType>paravirtual</virtualizationType> |
| | <clientToken>foo</clientToken> |
| | <tagSet> |
| | <item> |
| | <key>Name</key> |
| | <value/> |
| | </item> |
| | </tagSet> |
| | <hypervisor>xen</hypervisor> |
| | <networkInterfaceSet> |
| | <item> |
| | <networkInterfaceId>eni-id</networkInterfaceId> |
| | <subnetId>subnet-id</subnetId> |
| | <vpcId>vpc-id</vpcId> |
| | <description>Primary network interface</description> |
| | <ownerId>ownerid</ownerId> |
| | <status>in-use</status> |
| | <privateIpAddress>10.0.0.67</privateIpAddress> |
| | <sourceDestCheck>true</sourceDestCheck> |
| | <groupSet> |
| | <item> |
| | <groupId>sg-id</groupId> |
| | <groupName>WebServerSG</groupName> |
| | </item> |
| | </groupSet> |
| | <attachment> |
| | <attachmentId>eni-attach-id</attachmentId> |
| | <deviceIndex>0</deviceIndex> |
| | <status>attached</status> |
| | <attachTime>2012-12-14T23:48:37.000Z</attachTime> |
| | <deleteOnTermination>true</deleteOnTermination> |
| | </attachment> |
| | <privateIpAddressesSet> |
| | <item> |
| | <privateIpAddress>10.0.0.67</privateIpAddress> |
| | <primary>true</primary> |
| | </item> |
| | <item> |
| | <privateIpAddress>10.0.0.54</privateIpAddress> |
| | <primary>false</primary> |
| | </item> |
| | <item> |
| | <privateIpAddress>10.0.0.55</privateIpAddress> |
| | <primary>false</primary> |
| | </item> |
| | </privateIpAddressesSet> |
| | </item> |
| | </networkInterfaceSet> |
| | <ebsOptimized>false</ebsOptimized> |
| | </item> |
| | </instancesSet> |
| | </item> |
| | </reservationSet> |
| | </DescribeInstancesResponse> |
| | """""" |
| |
|
| | RUN_INSTANCE_RESPONSE = r"""""" |
| | <RunInstancesResponse xmlns=""http: |
| | <requestId>ad4b83c2-f606-4c39-90c6-5dcc5be823e1</requestId> |
| | <reservationId>r-c5cef7a7</reservationId> |
| | <ownerId>ownerid</ownerId> |
| | <groupSet> |
| | <item> |
| | <groupId>sg-id</groupId> |
| | <groupName>SSH</groupName> |
| | </item> |
| | </groupSet> |
| | <instancesSet> |
| | <item> |
| | <instanceId>i-ff0f1299</instanceId> |
| | <imageId>ami-ed65ba84</imageId> |
| | <instanceState> |
| | <code>0</code> |
| | <name>pending</name> |
| | </instanceState> |
| | <privateDnsName/> |
| | <dnsName/> |
| | <reason/> |
| | <keyName>awskeypair</keyName> |
| | <amiLaunchIndex>0</amiLaunchIndex> |
| | <productCodes/> |
| | <instanceType>t1.micro</instanceType> |
| | <launchTime>2012-05-30T19:21:18.000Z</launchTime> |
| | <placement> |
| | <availabilityZone>us-east-1a</availabilityZone> |
| | <groupName/> |
| | <tenancy>default</tenancy> |
| | </placement> |
| | <kernelId>aki-b6aa75df</kernelId> |
| | <monitoring> |
| | <state>disabled</state> |
| | </monitoring> |
| | <groupSet> |
| | <item> |
| | <groupId>sg-99a710f1</groupId> |
| | <groupName>SSH</groupName> |
| | </item> |
| | </groupSet> |
| | <stateReason> |
| | <code>pending</code> |
| | <message>pending</message> |
| | </stateReason> |
| | <architecture>i386</architecture> |
| | <rootDeviceType>ebs</rootDeviceType> |
| | <rootDeviceName>/dev/sda1</rootDeviceName> |
| | <blockDeviceMapping/> |
| | <virtualizationType>paravirtual</virtualizationType> |
| | <clientToken/> |
| | <hypervisor>xen</hypervisor> |
| | <networkInterfaceSet/> |
| | <iamInstanceProfile> |
| | <arn>arn:aws:iam::ownerid:instance-profile/myinstanceprofile</arn> |
| | <id>iamid</id> |
| | </iamInstanceProfile> |
| | </item> |
| | </instancesSet> |
| | </RunInstancesResponse> |
| | """""" |
| |
|
| |
|
| | class TestRunInstanceResponseParsing(unittest.TestCase): |
| | def testIAMInstanceProfileParsedCorrectly(self): |
| | ec2 = EC2Connection(aws_access_key_id='aws_access_key_id', |
| | aws_secret_access_key='aws_secret_access_key') |
| | mock_response = mock.Mock() |
| | mock_response.read.return_value = RUN_INSTANCE_RESPONSE |
| | mock_response.status = 200 |
| | ec2.make_request = mock.Mock(return_value=mock_response) |
| | reservation = ec2.run_instances(image_id='ami-12345') |
| | self.assertEqual(len(reservation.instances), 1) |
| | instance = reservation.instances[0] |
| | self.assertEqual(instance.image_id, 'ami-ed65ba84') |
| | # iamInstanceProfile has an ID element, so we want to make sure |
| | # that this does not map to instance.id (which should be the |
| | # id of the ec2 instance). |
| | self.assertEqual(instance.id, 'i-ff0f1299') |
| | self.assertDictEqual( |
| | instance.instance_profile, |
| | {'arn': ('arn:aws:iam::ownerid:' |
| | 'instance-profile/myinstanceprofile'), |
| | 'id': 'iamid'}) |
| |
|
| |
|
| | class TestDescribeInstances(AWSMockServiceTestCase): |
| | connection_class = EC2Connection |
| |
|
| | def default_body(self): |
| | return DESCRIBE_INSTANCE_VPC |
| |
|
| | def test_multiple_private_ip_addresses(self): |
| | self.set_http_response(status_code=200) |
| |
|
| | api_response = self.service_connection.get_all_reservations() |
| | self.assertEqual(len(api_response), 1) |
| |
|
| | instances = api_response[0].instances |
| | self.assertEqual(len(instances), 1) |
| |
|
| | instance = instances[0] |
| | self.assertEqual(len(instance.interfaces), 1) |
| |
|
| | interface = instance.interfaces[0] |
| | self.assertEqual(len(interface.private_ip_addresses), 3) |
| |
|
| | addresses = interface.private_ip_addresses |
| | self.assertEqual(addresses[0].private_ip_address, '10.0.0.67') |
| | self.assertTrue(addresses[0].primary) |
| |
|
| | self.assertEqual(addresses[1].private_ip_address, '10.0.0.54') |
| | self.assertFalse(addresses[1].primary) |
| |
|
| | self.assertEqual(addresses[2].private_ip_address, '10.0.0.55') |
| | self.assertFalse(addresses[2].primary) |
| |
|
| |
|
| | if __name__ == '__main__': |
| | unittest.main() |
| | ",harshilasu/GraphicMelon,y/google-cloud-sdk/platform/gsutil/third_party/boto/tests/unit/ec2/test_instance.py,Python,gpl-3.0,9932 |
| | 3," |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | package sun.awt.datatransfer; |
| |
|
| | import java.awt.EventQueue; |
| | import java.awt.Graphics; |
| | import java.awt.Image; |
| | import java.awt.Toolkit; |
| |
|
| | import java.awt.datatransfer.DataFlavor; |
| | import java.awt.datatransfer.FlavorMap; |
| | import java.awt.datatransfer.FlavorTable; |
| | import java.awt.datatransfer.Transferable; |
| | import java.awt.datatransfer.UnsupportedFlavorException; |
| |
|
| | import java.io.BufferedReader; |
| | import java.io.ByteArrayInputStream; |
| | import java.io.ByteArrayOutputStream; |
| | import java.io.File; |
| | import java.io.InputStream; |
| | import java.io.InputStreamReader; |
| | import java.io.IOException; |
| | import java.io.ObjectInputStream; |
| | import java.io.ObjectOutputStream; |
| | import java.io.Reader; |
| | import java.io.SequenceInputStream; |
| | import java.io.StringReader; |
| |
|
| | import java.net.URI; |
| | import java.net.URISyntaxException; |
| |
|
| | import java.nio.ByteBuffer; |
| | import java.nio.CharBuffer; |
| | import java.nio.charset.Charset; |
| | import java.nio.charset.CharsetEncoder; |
| | import java.nio.charset.IllegalCharsetNameException; |
| | import java.nio.charset.UnsupportedCharsetException; |
| |
|
| | import java.lang.reflect.Constructor; |
| | import java.lang.reflect.InvocationTargetException; |
| | import java.lang.reflect.Method; |
| | import java.lang.reflect.Modifier; |
| |
|
| | import java.security.AccessController; |
| | import java.security.PrivilegedAction; |
| | import java.security.PrivilegedActionException; |
| | import java.security.PrivilegedExceptionAction; |
| | import java.security.ProtectionDomain; |
| |
|
| | import java.util.ArrayList; |
| | import java.util.Arrays; |
| | import java.util.Collections; |
| | import java.util.Comparator; |
| | import java.util.HashMap; |
| | import java.util.HashSet; |
| | import java.util.Iterator; |
| | import java.util.List; |
| | import java.util.Map; |
| | import java.util.SortedMap; |
| | import java.util.SortedSet; |
| | import java.util.Set; |
| | import java.util.Stack; |
| | import java.util.TreeMap; |
| | import java.util.TreeSet; |
| |
|
| | import sun.awt.ComponentFactory; |
| | import sun.util.logging.PlatformLogger; |
| |
|
| | import sun.awt.AppContext; |
| | import sun.awt.SunToolkit; |
| |
|
| | import java.awt.image.BufferedImage; |
| | import java.awt.image.ImageObserver; |
| | import java.awt.image.RenderedImage; |
| | import java.awt.image.WritableRaster; |
| | import java.awt.image.ColorModel; |
| |
|
| | import javax.imageio.ImageIO; |
| | import javax.imageio.ImageReader; |
| | import javax.imageio.ImageReadParam; |
| | import javax.imageio.ImageWriter; |
| | import javax.imageio.ImageTypeSpecifier; |
| |
|
| | import javax.imageio.spi.ImageWriterSpi; |
| |
|
| | import javax.imageio.stream.ImageInputStream; |
| | import javax.imageio.stream.ImageOutputStream; |
| |
|
| | import sun.awt.image.ImageRepresentation; |
| | import sun.awt.image.ToolkitImage; |
| |
|
| | import java.io.FilePermission; |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public abstract class DataTransferer { |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public static final DataFlavor plainTextStringFlavor; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public static final DataFlavor javaTextEncodingFlavor; |
| |
|
| | |
| | |
| | |
| | private static class StandardEncodingsHolder { |
| | private static final SortedSet<String> standardEncodings = load(); |
| |
|
| | private static SortedSet<String> load() { |
| | final Comparator comparator = |
| | new CharsetComparator(IndexedComparator.SELECT_WORST); |
| | final SortedSet<String> tempSet = new TreeSet<String>(comparator); |
| | tempSet.add(""US-ASCII""); |
| | tempSet.add(""ISO-8859-1""); |
| | tempSet.add(""UTF-8""); |
| | tempSet.add(""UTF-16BE""); |
| | tempSet.add(""UTF-16LE""); |
| | tempSet.add(""UTF-16""); |
| | tempSet.add(getDefaultTextCharset()); |
| | return Collections.unmodifiableSortedSet(tempSet); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | private static final Map textMIMESubtypeCharsetSupport; |
| |
|
| | |
| | |
| | |
| | |
| | private static String defaultEncoding; |
| |
|
| | |
| | |
| | |
| | |
| | private static final Set textNatives = |
| | Collections.synchronizedSet(new HashSet()); |
| |
|
| | |
| | |
| | |
| | private static final Map nativeCharsets = |
| | Collections.synchronizedMap(new HashMap()); |
| |
|
| | |
| | |
| | |
| | private static final Map nativeEOLNs = |
| | Collections.synchronizedMap(new HashMap()); |
| |
|
| | |
| | |
| | |
| | private static final Map nativeTerminators = |
| | Collections.synchronizedMap(new HashMap()); |
| |
|
| | |
| | |
| | |
| | private static final String DATA_CONVERTER_KEY = ""DATA_CONVERTER_KEY""; |
| |
|
| | |
| | |
| | |
| | |
| | private static DataTransferer transferer; |
| |
|
| | private static final PlatformLogger dtLog = PlatformLogger.getLogger(""sun.awt.datatransfer.DataTransfer""); |
| |
|
| | static { |
| | DataFlavor tPlainTextStringFlavor = null; |
| | try { |
| | tPlainTextStringFlavor = new DataFlavor |
| | (""text/plain;charset=Unicode;class=java.lang.String""); |
| | } catch (ClassNotFoundException cannotHappen) { |
| | } |
| | plainTextStringFlavor = tPlainTextStringFlavor; |
| |
|
| | DataFlavor tJavaTextEncodingFlavor = null; |
| | try { |
| | tJavaTextEncodingFlavor = new DataFlavor |
| | (""application/x-java-text-encoding;class=\""[B\""""); |
| | } catch (ClassNotFoundException cannotHappen) { |
| | } |
| | javaTextEncodingFlavor = tJavaTextEncodingFlavor; |
| |
|
| | Map tempMap = new HashMap(17); |
| | tempMap.put(""sgml"", Boolean.TRUE); |
| | tempMap.put(""xml"", Boolean.TRUE); |
| | tempMap.put(""html"", Boolean.TRUE); |
| | tempMap.put(""enriched"", Boolean.TRUE); |
| | tempMap.put(""richtext"", Boolean.TRUE); |
| | tempMap.put(""uri-list"", Boolean.TRUE); |
| | tempMap.put(""directory"", Boolean.TRUE); |
| | tempMap.put(""css"", Boolean.TRUE); |
| | tempMap.put(""calendar"", Boolean.TRUE); |
| | tempMap.put(""plain"", Boolean.TRUE); |
| | tempMap.put(""rtf"", Boolean.FALSE); |
| | tempMap.put(""tab-separated-values"", Boolean.FALSE); |
| | tempMap.put(""t140"", Boolean.FALSE); |
| | tempMap.put(""rfc822-headers"", Boolean.FALSE); |
| | tempMap.put(""parityfec"", Boolean.FALSE); |
| | textMIMESubtypeCharsetSupport = Collections.synchronizedMap(tempMap); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | public static synchronized DataTransferer getInstance() { |
| | return ((ComponentFactory) Toolkit.getDefaultToolkit()).getDataTransferer(); |
| | } |
| |
|
| | |
| | |
| | |
| | public static String canonicalName(String encoding) { |
| | if (encoding == null) { |
| | return null; |
| | } |
| | try { |
| | return Charset.forName(encoding).name(); |
| | } catch (IllegalCharsetNameException icne) { |
| | return encoding; |
| | } catch (UnsupportedCharsetException uce) { |
| | return encoding; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public static String getTextCharset(DataFlavor flavor) { |
| | if (!isFlavorCharsetTextType(flavor)) { |
| | return null; |
| | } |
| |
|
| | String encoding = flavor.getParameter(""charset""); |
| |
|
| | return (encoding != null) ? encoding : getDefaultTextCharset(); |
| | } |
| |
|
| | |
| | |
| | |
| | public static String getDefaultTextCharset() { |
| | if (defaultEncoding != null) { |
| | return defaultEncoding; |
| | } |
| | return defaultEncoding = Charset.defaultCharset().name(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | public static boolean doesSubtypeSupportCharset(DataFlavor flavor) { |
| | if (dtLog.isLoggable(PlatformLogger.Level.FINE)) { |
| | if (!""text"".equals(flavor.getPrimaryType())) { |
| | dtLog.fine(""Assertion (\""text\"".equals(flavor.getPrimaryType())) failed""); |
| | } |
| | } |
| |
|
| | String subType = flavor.getSubType(); |
| | if (subType == null) { |
| | return false; |
| | } |
| |
|
| | Object support = textMIMESubtypeCharsetSupport.get(subType); |
| |
|
| | if (support != null) { |
| | return (support == Boolean.TRUE); |
| | } |
| |
|
| | boolean ret_val = (flavor.getParameter(""charset"") != null); |
| | textMIMESubtypeCharsetSupport.put |
| | (subType, (ret_val) ? Boolean.TRUE : Boolean.FALSE); |
| | return ret_val; |
| | } |
| | public static boolean doesSubtypeSupportCharset(String subType, |
| | String charset) |
| | { |
| | Object support = textMIMESubtypeCharsetSupport.get(subType); |
| |
|
| | if (support != null) { |
| | return (support == Boolean.TRUE); |
| | } |
| |
|
| | boolean ret_val = (charset != null); |
| | textMIMESubtypeCharsetSupport.put |
| | (subType, (ret_val) ? Boolean.TRUE : Boolean.FALSE); |
| | return ret_val; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | public static boolean isFlavorCharsetTextType(DataFlavor flavor) { |
| | |
| | |
| | |
| | |
| | if (DataFlavor.stringFlavor.equals(flavor)) { |
| | return true; |
| | } |
| |
|
| | if (!""text"".equals(flavor.getPrimaryType()) || |
| | !doesSubtypeSupportCharset(flavor)) |
| | { |
| | return false; |
| | } |
| |
|
| | Class rep_class = flavor.getRepresentationClass(); |
| |
|
| | if (flavor.isRepresentationClassReader() || |
| | String.class.equals(rep_class) || |
| | flavor.isRepresentationClassCharBuffer() || |
| | char[].class.equals(rep_class)) |
| | { |
| | return true; |
| | } |
| |
|
| | if (!(flavor.isRepresentationClassInputStream() || |
| | flavor.isRepresentationClassByteBuffer() || |
| | byte[].class.equals(rep_class))) { |
| | return false; |
| | } |
| |
|
| | String charset = flavor.getParameter(""charset""); |
| |
|
| | return (charset != null) |
| | ? DataTransferer.isEncodingSupported(charset) |
| | : true; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | public static boolean isFlavorNoncharsetTextType(DataFlavor flavor) { |
| | if (!""text"".equals(flavor.getPrimaryType()) || |
| | doesSubtypeSupportCharset(flavor)) |
| | { |
| | return false; |
| | } |
| |
|
| | return (flavor.isRepresentationClassInputStream() || |
| | flavor.isRepresentationClassByteBuffer() || |
| | byte[].class.equals(flavor.getRepresentationClass())); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | public static boolean isEncodingSupported(String encoding) { |
| | if (encoding == null) { |
| | return false; |
| | } |
| | try { |
| | return Charset.isSupported(encoding); |
| | } catch (IllegalCharsetNameException icne) { |
| | return false; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | public static boolean isRemote(Class<?> type) { |
| | return RMI.isRemote(type); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public static Set <String> standardEncodings() { |
| | return StandardEncodingsHolder.standardEncodings; |
| | } |
| |
|
| | |
| | |
| | |
| | public static FlavorTable adaptFlavorMap(final FlavorMap map) { |
| | if (map instanceof FlavorTable) { |
| | return (FlavorTable)map; |
| | } |
| |
|
| | return new FlavorTable() { |
| | public Map getNativesForFlavors(DataFlavor[] flavors) { |
| | return map.getNativesForFlavors(flavors); |
| | } |
| | public Map getFlavorsForNatives(String[] natives) { |
| | return map.getFlavorsForNatives(natives); |
| | } |
| | public List getNativesForFlavor(DataFlavor flav) { |
| | Map natives = |
| | getNativesForFlavors(new DataFlavor[] { flav } ); |
| | String nat = (String)natives.get(flav); |
| | if (nat != null) { |
| | List list = new ArrayList(1); |
| | list.add(nat); |
| | return list; |
| | } else { |
| | return Collections.EMPTY_LIST; |
| | } |
| | } |
| | public List getFlavorsForNative(String nat) { |
| | Map flavors = |
| | getFlavorsForNatives(new String[] { nat } ); |
| | DataFlavor flavor = (DataFlavor)flavors.get(nat); |
| | if (flavor != null) { |
| | List list = new ArrayList(1); |
| | list.add(flavor); |
| | return list; |
| | } else { |
| | return Collections.EMPTY_LIST; |
| | } |
| | } |
| | }; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | public abstract String getDefaultUnicodeEncoding(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public void registerTextFlavorProperties(String nat, String charset, |
| | String eoln, String terminators) { |
| | Long format = getFormatForNativeAsLong(nat); |
| |
|
| | textNatives.add(format); |
| | nativeCharsets.put(format, (charset != null && charset.length() != 0) |
| | ? charset : getDefaultTextCharset()); |
| | if (eoln != null && eoln.length() != 0 && !eoln.equals(""\n"")) { |
| | nativeEOLNs.put(format, eoln); |
| | } |
| | if (terminators != null && terminators.length() != 0) { |
| | Integer iTerminators = Integer.valueOf(terminators); |
| | if (iTerminators.intValue() > 0) { |
| | nativeTerminators.put(format, iTerminators); |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | protected boolean isTextFormat(long format) { |
| | return textNatives.contains(Long.valueOf(format)); |
| | } |
| |
|
| | protected String getCharsetForTextFormat(Long lFormat) { |
| | return (String)nativeCharsets.get(lFormat); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public abstract boolean isLocaleDependentTextFormat(long format); |
| |
|
| | |
| | |
| | |
| | |
| | public abstract boolean isFileFormat(long format); |
| |
|
| | |
| | |
| | |
| | |
| | public abstract boolean isImageFormat(long format); |
| |
|
| | |
| | |
| | |
| | |
| | protected boolean isURIListFormat(long format) { |
| | return false; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public SortedMap<Long,DataFlavor> getFormatsForTransferable( |
| | Transferable contents, FlavorTable map) |
| | { |
| | DataFlavor[] flavors = contents.getTransferDataFlavors(); |
| | if (flavors == null) { |
| | return new TreeMap(); |
| | } |
| | return getFormatsForFlavors(flavors, map); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public SortedMap getFormatsForFlavor(DataFlavor flavor, FlavorTable map) { |
| | return getFormatsForFlavors(new DataFlavor[] { flavor }, |
| | map); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public SortedMap <Long, DataFlavor> getFormatsForFlavors( |
| | DataFlavor[] flavors, FlavorTable map) |
| | { |
| | Map <Long,DataFlavor> formatMap = |
| | new HashMap <> (flavors.length); |
| | Map <Long,DataFlavor> textPlainMap = |
| | new HashMap <> (flavors.length); |
| | |
| | |
| | |
| | Map indexMap = new HashMap(flavors.length); |
| | Map textPlainIndexMap = new HashMap(flavors.length); |
| |
|
| | int currentIndex = 0; |
| |
|
| | |
| | |
| | |
| | for (int i = flavors.length - 1; i >= 0; i--) { |
| | DataFlavor flavor = flavors[i]; |
| | if (flavor == null) continue; |
| |
|
| | |
| | |
| | if (flavor.isFlavorTextType() || |
| | flavor.isFlavorJavaFileListType() || |
| | DataFlavor.imageFlavor.equals(flavor) || |
| | flavor.isRepresentationClassSerializable() || |
| | flavor.isRepresentationClassInputStream() || |
| | flavor.isRepresentationClassRemote()) |
| | { |
| | List natives = map.getNativesForFlavor(flavor); |
| |
|
| | currentIndex += natives.size(); |
| |
|
| | for (Iterator iter = natives.iterator(); iter.hasNext(); ) { |
| | Long lFormat = |
| | getFormatForNativeAsLong((String)iter.next()); |
| | Integer index = Integer.valueOf(currentIndex--); |
| |
|
| | formatMap.put(lFormat, flavor); |
| | indexMap.put(lFormat, index); |
| |
|
| | |
| | |
| | |
| | |
| | if ((""text"".equals(flavor.getPrimaryType()) && |
| | ""plain"".equals(flavor.getSubType())) || |
| | flavor.equals(DataFlavor.stringFlavor)) |
| | { |
| | textPlainMap.put(lFormat, flavor); |
| | textPlainIndexMap.put(lFormat, index); |
| | } |
| | } |
| |
|
| | currentIndex += natives.size(); |
| | } |
| | } |
| |
|
| | formatMap.putAll(textPlainMap); |
| | indexMap.putAll(textPlainIndexMap); |
| |
|
| | |
| | Comparator comparator = |
| | new IndexOrderComparator(indexMap, IndexedComparator.SELECT_WORST); |
| | SortedMap sortedMap = new TreeMap(comparator); |
| | sortedMap.putAll(formatMap); |
| |
|
| | return sortedMap; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | public long[] getFormatsForTransferableAsArray(Transferable contents, |
| | FlavorTable map) { |
| | return keysToLongArray(getFormatsForTransferable(contents, map)); |
| | } |
| | public long[] getFormatsForFlavorAsArray(DataFlavor flavor, |
| | FlavorTable map) { |
| | return keysToLongArray(getFormatsForFlavor(flavor, map)); |
| | } |
| | public long[] getFormatsForFlavorsAsArray(DataFlavor[] flavors, |
| | FlavorTable map) { |
| | return keysToLongArray(getFormatsForFlavors(flavors, map)); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public Map getFlavorsForFormat(long format, FlavorTable map) { |
| | return getFlavorsForFormats(new long[] { format }, map); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public Map getFlavorsForFormats(long[] formats, FlavorTable map) { |
| | Map flavorMap = new HashMap(formats.length); |
| | Set mappingSet = new HashSet(formats.length); |
| | Set flavorSet = new HashSet(formats.length); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | for (int i = 0; i < formats.length; i++) { |
| | long format = formats[i]; |
| | String nat = getNativeForFormat(format); |
| | List flavors = map.getFlavorsForNative(nat); |
| |
|
| | for (Iterator iter = flavors.iterator(); iter.hasNext(); ) { |
| | DataFlavor flavor = (DataFlavor)iter.next(); |
| |
|
| | |
| | |
| | if (flavor.isFlavorTextType() || |
| | flavor.isFlavorJavaFileListType() || |
| | DataFlavor.imageFlavor.equals(flavor) || |
| | flavor.isRepresentationClassSerializable() || |
| | flavor.isRepresentationClassInputStream() || |
| | flavor.isRepresentationClassRemote()) |
| | { |
| | Long lFormat = Long.valueOf(format); |
| | Object mapping = |
| | DataTransferer.createMapping(lFormat, flavor); |
| | flavorMap.put(flavor, lFormat); |
| | mappingSet.add(mapping); |
| | flavorSet.add(flavor); |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | for (Iterator flavorIter = flavorSet.iterator(); |
| | flavorIter.hasNext(); ) { |
| | DataFlavor flavor = (DataFlavor)flavorIter.next(); |
| |
|
| | List natives = map.getNativesForFlavor(flavor); |
| |
|
| | for (Iterator nativeIter = natives.iterator(); |
| | nativeIter.hasNext(); ) { |
| | Long lFormat = |
| | getFormatForNativeAsLong((String)nativeIter.next()); |
| | Object mapping = DataTransferer.createMapping(lFormat, flavor); |
| |
|
| | if (mappingSet.contains(mapping)) { |
| | flavorMap.put(flavor, lFormat); |
| | break; |
| | } |
| | } |
| | } |
| |
|
| | return flavorMap; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public Set getFlavorsForFormatsAsSet(long[] formats, FlavorTable map) { |
| | Set flavorSet = new HashSet(formats.length); |
| |
|
| | for (int i = 0; i < formats.length; i++) { |
| | String nat = getNativeForFormat(formats[i]); |
| | List flavors = map.getFlavorsForNative(nat); |
| |
|
| | for (Iterator iter = flavors.iterator(); iter.hasNext(); ) { |
| | DataFlavor flavor = (DataFlavor)iter.next(); |
| |
|
| | |
| | |
| | if (flavor.isFlavorTextType() || |
| | flavor.isFlavorJavaFileListType() || |
| | DataFlavor.imageFlavor.equals(flavor) || |
| | flavor.isRepresentationClassSerializable() || |
| | flavor.isRepresentationClassInputStream() || |
| | flavor.isRepresentationClassRemote()) |
| | { |
| | flavorSet.add(flavor); |
| | } |
| | } |
| | } |
| |
|
| | return flavorSet; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public DataFlavor[] getFlavorsForFormatAsArray(long format, |
| | FlavorTable map) { |
| | return getFlavorsForFormatsAsArray(new long[] { format }, map); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public DataFlavor[] getFlavorsForFormatsAsArray(long[] formats, |
| | FlavorTable map) { |
| | |
| | |
| | return setToSortedDataFlavorArray(getFlavorsForFormatsAsSet(formats, map)); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | private static Object createMapping(Object key, Object value) { |
| | |
| | |
| | return Arrays.asList(new Object[] { key, value }); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | protected abstract Long getFormatForNativeAsLong(String str); |
| |
|
| | |
| | |
| | |
| | |
| | protected abstract String getNativeForFormat(long format); |
| |
|
| | |
| | |
| | |
| | |
| | private String getBestCharsetForTextFormat(Long lFormat, |
| | Transferable localeTransferable) throws IOException |
| | { |
| | String charset = null; |
| | if (localeTransferable != null && |
| | isLocaleDependentTextFormat(lFormat) && |
| | localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) |
| | { |
| | try { |
| | charset = new String( |
| | (byte[])localeTransferable.getTransferData(javaTextEncodingFlavor), |
| | ""UTF-8"" |
| | ); |
| | } catch (UnsupportedFlavorException cannotHappen) { |
| | } |
| | } else { |
| | charset = getCharsetForTextFormat(lFormat); |
| | } |
| | if (charset == null) { |
| | |
| | charset = getDefaultTextCharset(); |
| | } |
| | return charset; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | private byte[] translateTransferableString(String str, |
| | long format) throws IOException |
| | { |
| | Long lFormat = Long.valueOf(format); |
| | String charset = getBestCharsetForTextFormat(lFormat, null); |
| | |
| | |
| | |
| | |
| | String eoln = (String)nativeEOLNs.get(lFormat); |
| | if (eoln != null) { |
| | int length = str.length(); |
| | StringBuffer buffer = |
| | new StringBuffer(length * 2); |
| | for (int i = 0; i < length; i++) { |
| | |
| | if (str.startsWith(eoln, i)) { |
| | buffer.append(eoln); |
| | i += eoln.length() - 1; |
| | continue; |
| | } |
| | char c = str.charAt(i); |
| | if (c == '\n') { |
| | buffer.append(eoln); |
| | } else { |
| | buffer.append(c); |
| | } |
| | } |
| | str = buffer.toString(); |
| | } |
| |
|
| | |
| | byte[] bytes = str.getBytes(charset); |
| |
|
| | |
| | |
| | |
| | |
| | Integer terminators = (Integer)nativeTerminators.get(lFormat); |
| | if (terminators != null) { |
| | int numTerminators = terminators.intValue(); |
| | byte[] terminatedBytes = |
| | new byte[bytes.length + numTerminators]; |
| | System.arraycopy(bytes, 0, terminatedBytes, 0, bytes.length); |
| | for (int i = bytes.length; i < terminatedBytes.length; i++) { |
| | terminatedBytes[i] = 0x0; |
| | } |
| | bytes = terminatedBytes; |
| | } |
| | return bytes; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | private String translateBytesToString(byte[] bytes, long format, |
| | Transferable localeTransferable) |
| | throws IOException |
| | { |
| |
|
| | Long lFormat = Long.valueOf(format); |
| | String charset = getBestCharsetForTextFormat(lFormat, localeTransferable); |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | String eoln = (String)nativeEOLNs.get(lFormat); |
| | Integer terminators = (Integer)nativeTerminators.get(lFormat); |
| | int count; |
| | if (terminators != null) { |
| | int numTerminators = terminators.intValue(); |
| | search: |
| | for (count = 0; count < (bytes.length - numTerminators + 1); count += numTerminators) { |
| | for (int i = count; i < count + numTerminators; i++) { |
| | if (bytes[i] != 0x0) { |
| | continue search; |
| | } |
| | } |
| | |
| | break search; |
| | } |
| | } else { |
| | count = bytes.length; |
| | } |
| |
|
| | |
| | String converted = new String(bytes, 0, count, charset); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | if (eoln != null) { |
| |
|
| | |
| | |
| | |
| |
|
| | char[] buf = converted.toCharArray(); |
| | char[] eoln_arr = eoln.toCharArray(); |
| | converted = null; |
| | int j = 0; |
| | boolean match; |
| |
|
| | for (int i = 0; i < buf.length; ) { |
| | |
| | if (i + eoln_arr.length > buf.length) { |
| | buf[j++] = buf[i++]; |
| | continue; |
| | } |
| |
|
| | match = true; |
| | for (int k = 0, l = i; k < eoln_arr.length; k++, l++) { |
| | if (eoln_arr[k] != buf[l]) { |
| | match = false; |
| | break; |
| | } |
| | } |
| | if (match) { |
| | buf[j++] = '\n'; |
| | i += eoln_arr.length; |
| | } else { |
| | buf[j++] = buf[i++]; |
| | } |
| | } |
| | converted = new String(buf, 0, j); |
| | } |
| |
|
| | return converted; |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | public byte[] translateTransferable(Transferable contents, |
| | DataFlavor flavor, |
| | long format) throws IOException |
| | { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | Object obj; |
| | boolean stringSelectionHack; |
| | try { |
| | obj = contents.getTransferData(flavor); |
| | if (obj == null) { |
| | return null; |
| | } |
| | if (flavor.equals(DataFlavor.plainTextFlavor) && |
| | !(obj instanceof InputStream)) |
| | { |
| | obj = contents.getTransferData(DataFlavor.stringFlavor); |
| | if (obj == null) { |
| | return null; |
| | } |
| | stringSelectionHack = true; |
| | } else { |
| | stringSelectionHack = false; |
| | } |
| | } catch (UnsupportedFlavorException e) { |
| | throw new IOException(e.getMessage()); |
| | } |
| |
|
| | |
| | |
| | if (stringSelectionHack || |
| | (String.class.equals(flavor.getRepresentationClass()) && |
| | isFlavorCharsetTextType(flavor) && isTextFormat(format))) { |
| |
|
| | String str = removeSuspectedData(flavor, contents, (String)obj); |
| |
|
| | return translateTransferableString( |
| | str, |
| | format); |
| |
|
| | |
| | |
| | } else if (flavor.isRepresentationClassReader()) { |
| | if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) { |
| | throw new IOException |
| | (""cannot transfer non-text data as Reader""); |
| | } |
| |
|
| | StringBuffer buf = new StringBuffer(); |
| | try (Reader r = (Reader)obj) { |
| | int c; |
| | while ((c = r.read()) != -1) { |
| | buf.append((char)c); |
| | } |
| | } |
| |
|
| | return translateTransferableString( |
| | buf.toString(), |
| | format); |
| |
|
| | |
| | } else if (flavor.isRepresentationClassCharBuffer()) { |
| | if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) { |
| | throw new IOException |
| | (""cannot transfer non-text data as CharBuffer""); |
| | } |
| |
|
| | CharBuffer buffer = (CharBuffer)obj; |
| | int size = buffer.remaining(); |
| | char[] chars = new char[size]; |
| | buffer.get(chars, 0, size); |
| |
|
| | return translateTransferableString( |
| | new String(chars), |
| | format); |
| |
|
| | |
| | } else if (char[].class.equals(flavor.getRepresentationClass())) { |
| | if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) { |
| | throw new IOException |
| | (""cannot transfer non-text data as char array""); |
| | } |
| |
|
| | return translateTransferableString( |
| | new String((char[])obj), |
| | format); |
| |
|
| | |
| | |
| | |
| | } else if (flavor.isRepresentationClassByteBuffer()) { |
| | ByteBuffer buffer = (ByteBuffer)obj; |
| | int size = buffer.remaining(); |
| | byte[] bytes = new byte[size]; |
| | buffer.get(bytes, 0, size); |
| |
|
| | if (isFlavorCharsetTextType(flavor) && isTextFormat(format)) { |
| | String sourceEncoding = DataTransferer.getTextCharset(flavor); |
| | return translateTransferableString( |
| | new String(bytes, sourceEncoding), |
| | format); |
| | } else { |
| | return bytes; |
| | } |
| |
|
| | |
| | |
| | |
| | } else if (byte[].class.equals(flavor.getRepresentationClass())) { |
| | byte[] bytes = (byte[])obj; |
| |
|
| | if (isFlavorCharsetTextType(flavor) && isTextFormat(format)) { |
| | String sourceEncoding = DataTransferer.getTextCharset(flavor); |
| | return translateTransferableString( |
| | new String(bytes, sourceEncoding), |
| | format); |
| | } else { |
| | return bytes; |
| | } |
| | |
| | } else if (DataFlavor.imageFlavor.equals(flavor)) { |
| | if (!isImageFormat(format)) { |
| | throw new IOException(""Data translation failed: "" + |
| | ""not an image format""); |
| | } |
| |
|
| | Image image = (Image)obj; |
| | byte[] bytes = imageToPlatformBytes(image, format); |
| |
|
| | if (bytes == null) { |
| | throw new IOException(""Data translation failed: "" + |
| | ""cannot convert java image to native format""); |
| | } |
| | return bytes; |
| | } |
| |
|
| | byte[] theByteArray = null; |
| |
|
| | |
| | |
| | if (isFileFormat(format)) { |
| | if (!DataFlavor.javaFileListFlavor.equals(flavor)) { |
| | throw new IOException(""data translation failed""); |
| | } |
| |
|
| | final List list = (List)obj; |
| |
|
| | final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents); |
| |
|
| | final ArrayList<String> fileList = castToFiles(list, userProtectionDomain); |
| |
|
| | try (ByteArrayOutputStream bos = convertFileListToBytes(fileList)) { |
| | theByteArray = bos.toByteArray(); |
| | } |
| |
|
| | |
| | |
| | } else if (isURIListFormat(format)) { |
| | if (!DataFlavor.javaFileListFlavor.equals(flavor)) { |
| | throw new IOException(""data translation failed""); |
| | } |
| | String nat = getNativeForFormat(format); |
| | String targetCharset = null; |
| | if (nat != null) { |
| | try { |
| | targetCharset = new DataFlavor(nat).getParameter(""charset""); |
| | } catch (ClassNotFoundException cnfe) { |
| | throw new IOException(cnfe); |
| | } |
| | } |
| | if (targetCharset == null) { |
| | targetCharset = ""UTF-8""; |
| | } |
| | final List list = (List)obj; |
| | final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents); |
| | final ArrayList<String> fileList = castToFiles(list, userProtectionDomain); |
| | final ArrayList<String> uriList = new ArrayList<String>(fileList.size()); |
| | for (String fileObject : fileList) { |
| | final URI uri = new File(fileObject).toURI(); |
| | |
| | try { |
| | uriList.add(new URI(uri.getScheme(), """", uri.getPath(), uri.getFragment()).toString()); |
| | } catch (URISyntaxException uriSyntaxException) { |
| | throw new IOException(uriSyntaxException); |
| | } |
| | } |
| |
|
| | byte[] eoln = ""\r\n"".getBytes(targetCharset); |
| |
|
| | try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { |
| | for (int i = 0; i < uriList.size(); i++) { |
| | byte[] bytes = uriList.get(i).getBytes(targetCharset); |
| | bos.write(bytes, 0, bytes.length); |
| | bos.write(eoln, 0, eoln.length); |
| | } |
| | theByteArray = bos.toByteArray(); |
| | } |
| |
|
| | |
| | |
| | |
| | } else if (flavor.isRepresentationClassInputStream()) { |
| | try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { |
| | try (InputStream is = (InputStream)obj) { |
| | boolean eof = false; |
| | int avail = is.available(); |
| | byte[] tmp = new byte[avail > 8192 ? avail : 8192]; |
| | do { |
| | int aValue; |
| | if (!(eof = (aValue = is.read(tmp, 0, tmp.length)) == -1)) { |
| | bos.write(tmp, 0, aValue); |
| | } |
| | } while (!eof); |
| | } |
| |
|
| | if (isFlavorCharsetTextType(flavor) && isTextFormat(format)) { |
| | byte[] bytes = bos.toByteArray(); |
| | String sourceEncoding = DataTransferer.getTextCharset(flavor); |
| | return translateTransferableString( |
| | new String(bytes, sourceEncoding), |
| | format); |
| | } |
| | theByteArray = bos.toByteArray(); |
| | } |
| |
|
| |
|
| |
|
| | |
| | } else if (flavor.isRepresentationClassRemote()) { |
| |
|
| | Object mo = RMI.newMarshalledObject(obj); |
| | theByteArray = convertObjectToBytes(mo); |
| |
|
| | |
| | } else if (flavor.isRepresentationClassSerializable()) { |
| |
|
| | theByteArray = convertObjectToBytes(obj); |
| |
|
| | } else { |
| | throw new IOException(""data translation failed""); |
| | } |
| |
|
| |
|
| |
|
| | return theByteArray; |
| | } |
| |
|
| | private static byte[] convertObjectToBytes(Object object) throws IOException { |
| | try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| | ObjectOutputStream oos = new ObjectOutputStream(bos)) |
| | { |
| | oos.writeObject(object); |
| | return bos.toByteArray(); |
| | } |
| | } |
| |
|
| | protected abstract ByteArrayOutputStream convertFileListToBytes(ArrayList<String> fileList) throws IOException; |
| |
|
| | private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str) |
| | throws IOException |
| | { |
| | if (null == System.getSecurityManager() |
| | || !flavor.isMimeTypeEqual(""text/uri-list"")) |
| | { |
| | return str; |
| | } |
| |
|
| |
|
| | String ret_val = """"; |
| | final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents); |
| |
|
| | try { |
| | ret_val = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() { |
| | public Object run() { |
| |
|
| | StringBuffer allowedFiles = new StringBuffer(str.length()); |
| | String [] uriArray = str.split(""(\\s)+""); |
| |
|
| | for (String fileName : uriArray) |
| | { |
| | File file = new File(fileName); |
| | if (file.exists() && |
| | !(isFileInWebstartedCache(file) || |
| | isForbiddenToRead(file, userProtectionDomain))) |
| | { |
| |
|
| | if (0 != allowedFiles.length()) |
| | { |
| | allowedFiles.append(""\\r\\n""); |
| | } |
| |
|
| | allowedFiles.append(fileName); |
| | } |
| | } |
| |
|
| | return allowedFiles.toString(); |
| | } |
| | }); |
| | } catch (PrivilegedActionException pae) { |
| | throw new IOException(pae.getMessage(), pae); |
| | } |
| |
|
| | return ret_val; |
| | } |
| |
|
| | private static ProtectionDomain getUserProtectionDomain(Transferable contents) { |
| | return contents.getClass().getProtectionDomain(); |
| | } |
| |
|
| | private boolean isForbiddenToRead (File file, ProtectionDomain protectionDomain) |
| | { |
| | if (null == protectionDomain) { |
| | return false; |
| | } |
| | try { |
| | FilePermission filePermission = |
| | new FilePermission(file.getCanonicalPath(), ""read, delete""); |
| | if (protectionDomain.implies(filePermission)) { |
| | return false; |
| | } |
| | } catch (IOException e) {} |
| |
|
| | return true; |
| | } |
| |
|
| | private ArrayList<String> castToFiles(final List files, |
| | final ProtectionDomain userProtectionDomain) throws IOException |
| | { |
| | final ArrayList<String> fileList = new ArrayList<String>(); |
| | try { |
| | AccessController.doPrivileged(new PrivilegedExceptionAction() { |
| | public Object run() throws IOException { |
| | for (Object fileObject : files) |
| | { |
| | File file = castToFile(fileObject); |
| | if (file != null && |
| | (null == System.getSecurityManager() || |
| | !(isFileInWebstartedCache(file) || |
| | isForbiddenToRead(file, userProtectionDomain)))) |
| | { |
| | fileList.add(file.getCanonicalPath()); |
| | } |
| | } |
| | return null; |
| | } |
| | }); |
| | } catch (PrivilegedActionException pae) { |
| | throw new IOException(pae.getMessage()); |
| | } |
| | return fileList; |
| | } |
| |
|
| | |
| | |
| | private File castToFile(Object fileObject) throws IOException { |
| | String filePath = null; |
| | if (fileObject instanceof File) { |
| | filePath = ((File)fileObject).getCanonicalPath(); |
| | } else if (fileObject instanceof String) { |
| | filePath = (String) fileObject; |
| | } else { |
| | return null; |
| | } |
| | return new File(filePath); |
| | } |
| |
|
| | private final static String[] DEPLOYMENT_CACHE_PROPERTIES = { |
| | ""deployment.system.cachedir"", |
| | ""deployment.user.cachedir"", |
| | ""deployment.javaws.cachedir"", |
| | ""deployment.javapi.cachedir"" |
| | }; |
| |
|
| | private final static ArrayList <File> deploymentCacheDirectoryList = |
| | new ArrayList<File>(); |
| |
|
| | private static boolean isFileInWebstartedCache(File f) { |
| |
|
| | if (deploymentCacheDirectoryList.isEmpty()) { |
| | for (String cacheDirectoryProperty : DEPLOYMENT_CACHE_PROPERTIES) { |
| | String cacheDirectoryPath = System.getProperty(cacheDirectoryProperty); |
| | if (cacheDirectoryPath != null) { |
| | try { |
| | File cacheDirectory = (new File(cacheDirectoryPath)).getCanonicalFile(); |
| | if (cacheDirectory != null) { |
| | deploymentCacheDirectoryList.add(cacheDirectory); |
| | } |
| | } catch (IOException ioe) {} |
| | } |
| | } |
| | } |
| |
|
| | for (File deploymentCacheDirectory : deploymentCacheDirectoryList) { |
| | for (File dir = f; dir != null; dir = dir.getParentFile()) { |
| | if (dir.equals(deploymentCacheDirectory)) { |
| | return true; |
| | } |
| | } |
| | } |
| |
|
| | return false; |
| | } |
| |
|
| |
|
| | public Object translateBytes(byte[] bytes, DataFlavor flavor, |
| | long format, Transferable localeTransferable) |
| | throws IOException |
| | { |
| |
|
| | Object theObject = null; |
| |
|
| | |
| | |
| | |
| | if (isFileFormat(format)) { |
| | if (!DataFlavor.javaFileListFlavor.equals(flavor)) { |
| | throw new IOException(""data translation failed""); |
| | } |
| | String[] filenames = dragQueryFile(bytes); |
| | if (filenames == null) { |
| | return null; |
| | } |
| |
|
| | |
| | File[] files = new File[filenames.length]; |
| | for (int i = 0; i < filenames.length; i++) { |
| | files[i] = new File(filenames[i]); |
| | } |
| |
|
| | |
| | theObject = Arrays.asList(files); |
| |
|
| | |
| | |
| | } else if (isURIListFormat(format) |
| | && DataFlavor.javaFileListFlavor.equals(flavor)) { |
| |
|
| | try (ByteArrayInputStream str = new ByteArrayInputStream(bytes)) { |
| |
|
| | URI uris[] = dragQueryURIs(str, format, localeTransferable); |
| | if (uris == null) { |
| | return null; |
| | } |
| | List<File> files = new ArrayList<>(); |
| | for (URI uri : uris) { |
| | try { |
| | files.add(new File(uri)); |
| | } catch (IllegalArgumentException illegalArg) { |
| | |
| | |
| | |
| | } |
| | } |
| | theObject = files; |
| | } |
| |
|
| | |
| | |
| | } else if (String.class.equals(flavor.getRepresentationClass()) && |
| | isFlavorCharsetTextType(flavor) && isTextFormat(format)) { |
| |
|
| | theObject = translateBytesToString(bytes, format, localeTransferable); |
| |
|
| | |
| | |
| | |
| | } else if (flavor.isRepresentationClassReader()) { |
| | try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) { |
| | theObject = translateStream(bais, |
| | flavor, format, localeTransferable); |
| | } |
| | |
| | } else if (flavor.isRepresentationClassCharBuffer()) { |
| | if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) { |
| | throw new IOException |
| | (""cannot transfer non-text data as CharBuffer""); |
| | } |
| |
|
| | CharBuffer buffer = CharBuffer.wrap( |
| | translateBytesToString(bytes,format, localeTransferable)); |
| |
|
| | theObject = constructFlavoredObject(buffer, flavor, CharBuffer.class); |
| |
|
| | |
| | |
| | } else if (char[].class.equals(flavor.getRepresentationClass())) { |
| | if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) { |
| | throw new IOException |
| | (""cannot transfer non-text data as char array""); |
| | } |
| |
|
| | theObject = translateBytesToString( |
| | bytes, format, localeTransferable).toCharArray(); |
| |
|
| | |
| | |
| | |
| | |
| | } else if (flavor.isRepresentationClassByteBuffer()) { |
| | if (isFlavorCharsetTextType(flavor) && isTextFormat(format)) { |
| | bytes = translateBytesToString( |
| | bytes, format, localeTransferable).getBytes( |
| | DataTransferer.getTextCharset(flavor) |
| | ); |
| | } |
| |
|
| | ByteBuffer buffer = ByteBuffer.wrap(bytes); |
| | theObject = constructFlavoredObject(buffer, flavor, ByteBuffer.class); |
| |
|
| | |
| | |
| | |
| | |
| | } else if (byte[].class.equals(flavor.getRepresentationClass())) { |
| | if (isFlavorCharsetTextType(flavor) && isTextFormat(format)) { |
| | theObject = translateBytesToString( |
| | bytes, format, localeTransferable |
| | ).getBytes(DataTransferer.getTextCharset(flavor)); |
| | } else { |
| | theObject = bytes; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | } else if (flavor.isRepresentationClassInputStream()) { |
| |
|
| | try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) { |
| | theObject = translateStream(bais, flavor, format, localeTransferable); |
| | } |
| |
|
| | } else if (flavor.isRepresentationClassRemote()) { |
| | try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes); |
| | ObjectInputStream ois = new ObjectInputStream(bais)) |
| | { |
| | theObject = RMI.getMarshalledObject(ois.readObject()); |
| | } catch (Exception e) { |
| | throw new IOException(e.getMessage()); |
| | } |
| |
|
| | |
| | } else if (flavor.isRepresentationClassSerializable()) { |
| |
|
| | try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) { |
| | theObject = translateStream(bais, flavor, format, localeTransferable); |
| | } |
| |
|
| | |
| | } else if (DataFlavor.imageFlavor.equals(flavor)) { |
| | if (!isImageFormat(format)) { |
| | throw new IOException(""data translation failed""); |
| | } |
| |
|
| | theObject = platformImageBytesToImage(bytes, format); |
| | } |
| |
|
| | if (theObject == null) { |
| | throw new IOException(""data translation failed""); |
| | } |
| |
|
| | return theObject; |
| |
|
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | public Object translateStream(InputStream str, DataFlavor flavor, |
| | long format, Transferable localeTransferable) |
| | throws IOException |
| | { |
| |
|
| | Object theObject = null; |
| | |
| | |
| | if (isURIListFormat(format) |
| | && DataFlavor.javaFileListFlavor.equals(flavor)) |
| | { |
| |
|
| | URI uris[] = dragQueryURIs(str, format, localeTransferable); |
| | if (uris == null) { |
| | return null; |
| | } |
| | ArrayList files = new ArrayList(); |
| | for (URI uri : uris) { |
| | try { |
| | files.add(new File(uri)); |
| | } catch (IllegalArgumentException illegalArg) { |
| | |
| | |
| | |
| | } |
| | } |
| | theObject = files; |
| |
|
| | |
| | |
| | } else if (String.class.equals(flavor.getRepresentationClass()) && |
| | isFlavorCharsetTextType(flavor) && isTextFormat(format)) { |
| |
|
| | return translateBytesToString(inputStreamToByteArray(str), |
| | format, localeTransferable); |
| |
|
| | |
| | |
| | |
| | } else if (DataFlavor.plainTextFlavor.equals(flavor)) { |
| | theObject = new StringReader(translateBytesToString( |
| | inputStreamToByteArray(str), |
| | format, localeTransferable)); |
| |
|
| | |
| | |
| | |
| | |
| | } else if (flavor.isRepresentationClassInputStream()) { |
| | theObject = translateStreamToInputStream(str, flavor, format, |
| | localeTransferable); |
| |
|
| | |
| | |
| | |
| | } else if (flavor.isRepresentationClassReader()) { |
| | if (!(isFlavorCharsetTextType(flavor) && isTextFormat(format))) { |
| | throw new IOException |
| | (""cannot transfer non-text data as Reader""); |
| | } |
| |
|
| | InputStream is = (InputStream)translateStreamToInputStream( |
| | str, DataFlavor.plainTextFlavor, |
| | format, localeTransferable); |
| |
|
| | String unicode = DataTransferer.getTextCharset(DataFlavor.plainTextFlavor); |
| |
|
| | Reader reader = new InputStreamReader(is, unicode); |
| |
|
| | theObject = constructFlavoredObject(reader, flavor, Reader.class); |
| | |
| | } else if (byte[].class.equals(flavor.getRepresentationClass())) { |
| | if(isFlavorCharsetTextType(flavor) && isTextFormat(format)) { |
| | theObject = translateBytesToString(inputStreamToByteArray(str), format, localeTransferable) |
| | .getBytes(DataTransferer.getTextCharset(flavor)); |
| | } else { |
| | theObject = inputStreamToByteArray(str); |
| | } |
| | |
| | } else if (flavor.isRepresentationClassRemote()) { |
| |
|
| | try (ObjectInputStream ois = |
| | new ObjectInputStream(str)) |
| | { |
| | theObject = RMI.getMarshalledObject(ois.readObject()); |
| | }catch (Exception e) { |
| | throw new IOException(e.getMessage()); |
| | } |
| |
|
| | |
| | } else if (flavor.isRepresentationClassSerializable()) { |
| | try (ObjectInputStream ois = |
| | new ObjectInputStream(str)) |
| | { |
| | theObject = ois.readObject(); |
| | } catch (Exception e) { |
| | throw new IOException(e.getMessage()); |
| | } |
| | |
| | } else if (DataFlavor.imageFlavor.equals(flavor)) { |
| | if (!isImageFormat(format)) { |
| | throw new IOException(""data translation failed""); |
| | } |
| | theObject = platformImageBytesToImage(inputStreamToByteArray(str), format); |
| | } |
| |
|
| | if (theObject == null) { |
| | throw new IOException(""data translation failed""); |
| | } |
| |
|
| | return theObject; |
| |
|
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | private Object translateStreamToInputStream |
| | (InputStream str, DataFlavor flavor, long format, |
| | Transferable localeTransferable) throws IOException |
| | { |
| | if (isFlavorCharsetTextType(flavor) && isTextFormat(format)) { |
| | str = new ReencodingInputStream |
| | (str, format, DataTransferer.getTextCharset(flavor), |
| | localeTransferable); |
| | } |
| |
|
| | return constructFlavoredObject(str, flavor, InputStream.class); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | private Object constructFlavoredObject(Object arg, DataFlavor flavor, |
| | Class clazz) |
| | throws IOException |
| | { |
| | final Class dfrc = flavor.getRepresentationClass(); |
| |
|
| | if (clazz.equals(dfrc)) { |
| | return arg; |
| | } else { |
| | Constructor[] constructors = null; |
| |
|
| | try { |
| | constructors = (Constructor[]) |
| | AccessController.doPrivileged(new PrivilegedAction() { |
| | public Object run() { |
| | return dfrc.getConstructors(); |
| | } |
| | }); |
| | } catch (SecurityException se) { |
| | throw new IOException(se.getMessage()); |
| | } |
| |
|
| | Constructor constructor = null; |
| |
|
| | for (int j = 0; j < constructors.length; j++) { |
| | if (!Modifier.isPublic(constructors[j].getModifiers())) { |
| | continue; |
| | } |
| |
|
| | Class[] ptypes = constructors[j].getParameterTypes(); |
| |
|
| | if (ptypes != null && ptypes.length == 1 && |
| | clazz.equals(ptypes[0])) { |
| | constructor = constructors[j]; |
| | break; |
| | } |
| | } |
| |
|
| | if (constructor == null) { |
| | throw new IOException(""can't find <init>(L""+ clazz + |
| | "";)V for class: "" + dfrc.getName()); |
| | } |
| |
|
| | try { |
| | return constructor.newInstance(new Object[] { arg } ); |
| | } catch (Exception e) { |
| | throw new IOException(e.getMessage()); |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | public class ReencodingInputStream extends InputStream { |
| | protected BufferedReader wrapped; |
| | protected final char[] in = new char[2]; |
| | protected byte[] out; |
| |
|
| | protected CharsetEncoder encoder; |
| | protected CharBuffer inBuf; |
| | protected ByteBuffer outBuf; |
| |
|
| | protected char[] eoln; |
| | protected int numTerminators; |
| |
|
| | protected boolean eos; |
| | protected int index, limit; |
| |
|
| | public ReencodingInputStream(InputStream bytestream, long format, |
| | String targetEncoding, |
| | Transferable localeTransferable) |
| | throws IOException |
| | { |
| | Long lFormat = Long.valueOf(format); |
| |
|
| | String sourceEncoding = null; |
| | if (isLocaleDependentTextFormat(format) && |
| | localeTransferable != null && |
| | localeTransferable. |
| | isDataFlavorSupported(javaTextEncodingFlavor)) |
| | { |
| | try { |
| | sourceEncoding = new String((byte[])localeTransferable. |
| | getTransferData(javaTextEncodingFlavor), |
| | ""UTF-8""); |
| | } catch (UnsupportedFlavorException cannotHappen) { |
| | } |
| | } else { |
| | sourceEncoding = getCharsetForTextFormat(lFormat); |
| | } |
| |
|
| | if (sourceEncoding == null) { |
| | |
| | sourceEncoding = getDefaultTextCharset(); |
| | } |
| | wrapped = new BufferedReader |
| | (new InputStreamReader(bytestream, sourceEncoding)); |
| |
|
| | if (targetEncoding == null) { |
| | |
| | |
| | |
| | |
| | throw new NullPointerException(""null target encoding""); |
| | } |
| |
|
| | try { |
| | encoder = Charset.forName(targetEncoding).newEncoder(); |
| | out = new byte[(int)(encoder.maxBytesPerChar() * 2 + 0.5)]; |
| | inBuf = CharBuffer.wrap(in); |
| | outBuf = ByteBuffer.wrap(out); |
| | } catch (IllegalCharsetNameException e) { |
| | throw new IOException(e.toString()); |
| | } catch (UnsupportedCharsetException e) { |
| | throw new IOException(e.toString()); |
| | } catch (UnsupportedOperationException e) { |
| | throw new IOException(e.toString()); |
| | } |
| |
|
| | String sEoln = (String)nativeEOLNs.get(lFormat); |
| | if (sEoln != null) { |
| | eoln = sEoln.toCharArray(); |
| | } |
| |
|
| | |
| | |
| | Integer terminators = (Integer)nativeTerminators.get(lFormat); |
| | if (terminators != null) { |
| | numTerminators = terminators.intValue(); |
| | } |
| | } |
| |
|
| | private int readChar() throws IOException { |
| | int c = wrapped.read(); |
| |
|
| | if (c == -1) { |
| | eos = true; |
| | return -1; |
| | } |
| |
|
| | |
| | if (numTerminators > 0 && c == 0) { |
| | eos = true; |
| | return -1; |
| | } else if (eoln != null && matchCharArray(eoln, c)) { |
| | c = '\n' & 0xFFFF; |
| | } |
| |
|
| | return c; |
| | } |
| |
|
| | public int read() throws IOException { |
| | if (eos) { |
| | return -1; |
| | } |
| |
|
| | if (index >= limit) { |
| | |
| | int c = readChar(); |
| | if (c == -1) { |
| | return -1; |
| | } |
| |
|
| | in[0] = (char) c; |
| | in[1] = 0; |
| | inBuf.limit(1); |
| | if (Character.isHighSurrogate((char) c)) { |
| | c = readChar(); |
| | if (c != -1) { |
| | in[1] = (char) c; |
| | inBuf.limit(2); |
| | } |
| | } |
| |
|
| | inBuf.rewind(); |
| | outBuf.limit(out.length).rewind(); |
| | encoder.encode(inBuf, outBuf, false); |
| | outBuf.flip(); |
| | limit = outBuf.limit(); |
| |
|
| | index = 0; |
| |
|
| | return read(); |
| | } else { |
| | return out[index++] & 0xFF; |
| | } |
| | } |
| |
|
| | public int available() throws IOException { |
| | return ((eos) ? 0 : (limit - index)); |
| | } |
| |
|
| | public void close() throws IOException { |
| | wrapped.close(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | private boolean matchCharArray(char[] array, int c) |
| | throws IOException |
| | { |
| | wrapped.mark(array.length); |
| |
|
| | int count = 0; |
| | if ((char)c == array[0]) { |
| | for (count = 1; count < array.length; count++) { |
| | c = wrapped.read(); |
| | if (c == -1 || ((char)c) != array[count]) { |
| | break; |
| | } |
| | } |
| | } |
| |
|
| | if (count == array.length) { |
| | return true; |
| | } else { |
| | wrapped.reset(); |
| | return false; |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | protected abstract String[] dragQueryFile(byte[] bytes); |
| |
|
| | |
| | |
| | |
| | protected URI[] dragQueryURIs(InputStream stream, |
| | long format, |
| | Transferable localeTransferable) |
| | throws IOException |
| | { |
| | throw new IOException( |
| | new UnsupportedOperationException(""not implemented on this platform"")); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| |
|
| |
|
| | protected abstract Image platformImageBytesToImage( |
| | byte[] bytes,long format) throws IOException; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | protected Image standardImageBytesToImage( |
| | byte[] bytes, String mimeType) throws IOException |
| | { |
| |
|
| | Iterator readerIterator = ImageIO.getImageReadersByMIMEType(mimeType); |
| |
|
| | if (!readerIterator.hasNext()) { |
| | throw new IOException(""No registered service provider can decode "" + |
| | "" an image from "" + mimeType); |
| | } |
| |
|
| | IOException ioe = null; |
| |
|
| | while (readerIterator.hasNext()) { |
| | ImageReader imageReader = (ImageReader)readerIterator.next(); |
| | try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) { |
| | ImageInputStream imageInputStream = |
| | ImageIO.createImageInputStream(bais); |
| |
|
| | try { |
| | ImageReadParam param = imageReader.getDefaultReadParam(); |
| | imageReader.setInput(imageInputStream, true, true); |
| | BufferedImage bufferedImage = |
| | imageReader.read(imageReader.getMinIndex(), param); |
| | if (bufferedImage != null) { |
| | return bufferedImage; |
| | } |
| | } finally { |
| | imageInputStream.close(); |
| | imageReader.dispose(); |
| | } |
| | } catch (IOException e) { |
| | ioe = e; |
| | continue; |
| | } |
| | } |
| |
|
| | if (ioe == null) { |
| | ioe = new IOException(""Registered service providers failed to decode"" |
| | + "" an image from "" + mimeType); |
| | } |
| |
|
| | throw ioe; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | protected abstract byte[] imageToPlatformBytes(Image image, long format) |
| | throws IOException; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | protected byte[] imageToStandardBytes(Image image, String mimeType) |
| | throws IOException { |
| | IOException originalIOE = null; |
| |
|
| | Iterator writerIterator = ImageIO.getImageWritersByMIMEType(mimeType); |
| |
|
| | if (!writerIterator.hasNext()) { |
| | throw new IOException(""No registered service provider can encode "" + |
| | "" an image to "" + mimeType); |
| | } |
| |
|
| | if (image instanceof RenderedImage) { |
| | |
| | try { |
| | return imageToStandardBytesImpl((RenderedImage)image, mimeType); |
| | } catch (IOException ioe) { |
| | originalIOE = ioe; |
| | } |
| | } |
| |
|
| | |
| | int width = 0; |
| | int height = 0; |
| | if (image instanceof ToolkitImage) { |
| | ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); |
| | ir.reconstruct(ImageObserver.ALLBITS); |
| | width = ir.getWidth(); |
| | height = ir.getHeight(); |
| | } else { |
| | width = image.getWidth(null); |
| | height = image.getHeight(null); |
| | } |
| |
|
| | ColorModel model = ColorModel.getRGBdefault(); |
| | WritableRaster raster = |
| | model.createCompatibleWritableRaster(width, height); |
| |
|
| | BufferedImage bufferedImage = |
| | new BufferedImage(model, raster, model.isAlphaPremultiplied(), |
| | null); |
| |
|
| | Graphics g = bufferedImage.getGraphics(); |
| | try { |
| | g.drawImage(image, 0, 0, width, height, null); |
| | } finally { |
| | g.dispose(); |
| | } |
| |
|
| | try { |
| | return imageToStandardBytesImpl(bufferedImage, mimeType); |
| | } catch (IOException ioe) { |
| | if (originalIOE != null) { |
| | throw originalIOE; |
| | } else { |
| | throw ioe; |
| | } |
| | } |
| | } |
| |
|
| | protected byte[] imageToStandardBytesImpl(RenderedImage renderedImage, |
| | String mimeType) |
| | throws IOException { |
| |
|
| | Iterator writerIterator = ImageIO.getImageWritersByMIMEType(mimeType); |
| |
|
| | ImageTypeSpecifier typeSpecifier = |
| | new ImageTypeSpecifier(renderedImage); |
| |
|
| | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | IOException ioe = null; |
| |
|
| | while (writerIterator.hasNext()) { |
| | ImageWriter imageWriter = (ImageWriter)writerIterator.next(); |
| | ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider(); |
| |
|
| | if (!writerSpi.canEncodeImage(typeSpecifier)) { |
| | continue; |
| | } |
| |
|
| | try { |
| | ImageOutputStream imageOutputStream = |
| | ImageIO.createImageOutputStream(baos); |
| | try { |
| | imageWriter.setOutput(imageOutputStream); |
| | imageWriter.write(renderedImage); |
| | imageOutputStream.flush(); |
| | } finally { |
| | imageOutputStream.close(); |
| | } |
| | } catch (IOException e) { |
| | imageWriter.dispose(); |
| | baos.reset(); |
| | ioe = e; |
| | continue; |
| | } |
| |
|
| | imageWriter.dispose(); |
| | baos.close(); |
| | return baos.toByteArray(); |
| | } |
| |
|
| | baos.close(); |
| |
|
| | if (ioe == null) { |
| | ioe = new IOException(""Registered service providers failed to encode "" |
| | + renderedImage + "" to "" + mimeType); |
| | } |
| |
|
| | throw ioe; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | private Object concatData(Object obj1, Object obj2) { |
| | InputStream str1 = null; |
| | InputStream str2 = null; |
| |
|
| | if (obj1 instanceof byte[]) { |
| | byte[] arr1 = (byte[])obj1; |
| | if (obj2 instanceof byte[]) { |
| | byte[] arr2 = (byte[])obj2; |
| | byte[] ret = new byte[arr1.length + arr2.length]; |
| | System.arraycopy(arr1, 0, ret, 0, arr1.length); |
| | System.arraycopy(arr2, 0, ret, arr1.length, arr2.length); |
| | return ret; |
| | } else { |
| | str1 = new ByteArrayInputStream(arr1); |
| | str2 = (InputStream)obj2; |
| | } |
| | } else { |
| | str1 = (InputStream)obj1; |
| | if (obj2 instanceof byte[]) { |
| | str2 = new ByteArrayInputStream((byte[])obj2); |
| | } else { |
| | str2 = (InputStream)obj2; |
| | } |
| | } |
| |
|
| | return new SequenceInputStream(str1, str2); |
| | } |
| |
|
| | public byte[] convertData(final Object source, |
| | final Transferable contents, |
| | final long format, |
| | final Map formatMap, |
| | final boolean isToolkitThread) |
| | throws IOException |
| | { |
| | byte[] ret = null; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | if (isToolkitThread) try { |
| | final Stack stack = new Stack(); |
| | final Runnable dataConverter = new Runnable() { |
| | |
| | private boolean done = false; |
| | public void run() { |
| | if (done) { |
| | return; |
| | } |
| | byte[] data = null; |
| | try { |
| | DataFlavor flavor = (DataFlavor)formatMap.get(Long.valueOf(format)); |
| | if (flavor != null) { |
| | data = translateTransferable(contents, flavor, format); |
| | } |
| | } catch (Exception e) { |
| | e.printStackTrace(); |
| | data = null; |
| | } |
| | try { |
| | getToolkitThreadBlockedHandler().lock(); |
| | stack.push(data); |
| | getToolkitThreadBlockedHandler().exit(); |
| | } finally { |
| | getToolkitThreadBlockedHandler().unlock(); |
| | done = true; |
| | } |
| | } |
| | }; |
| |
|
| | final AppContext appContext = SunToolkit.targetToAppContext(source); |
| |
|
| | getToolkitThreadBlockedHandler().lock(); |
| |
|
| | if (appContext != null) { |
| | appContext.put(DATA_CONVERTER_KEY, dataConverter); |
| | } |
| |
|
| | SunToolkit.executeOnEventHandlerThread(source, dataConverter); |
| |
|
| | while (stack.empty()) { |
| | getToolkitThreadBlockedHandler().enter(); |
| | } |
| |
|
| | if (appContext != null) { |
| | appContext.remove(DATA_CONVERTER_KEY); |
| | } |
| |
|
| | ret = (byte[])stack.pop(); |
| | } finally { |
| | getToolkitThreadBlockedHandler().unlock(); |
| | } else { |
| | DataFlavor flavor = (DataFlavor) |
| | formatMap.get(Long.valueOf(format)); |
| | if (flavor != null) { |
| | ret = translateTransferable(contents, flavor, format); |
| | } |
| | } |
| |
|
| | return ret; |
| | } |
| |
|
| | public void processDataConversionRequests() { |
| | if (EventQueue.isDispatchThread()) { |
| | AppContext appContext = AppContext.getAppContext(); |
| | getToolkitThreadBlockedHandler().lock(); |
| | try { |
| | Runnable dataConverter = |
| | (Runnable)appContext.get(DATA_CONVERTER_KEY); |
| | if (dataConverter != null) { |
| | dataConverter.run(); |
| | appContext.remove(DATA_CONVERTER_KEY); |
| | } |
| | } finally { |
| | getToolkitThreadBlockedHandler().unlock(); |
| | } |
| | } |
| | } |
| |
|
| | public abstract ToolkitThreadBlockedHandler |
| | getToolkitThreadBlockedHandler(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public static long[] keysToLongArray(SortedMap map) { |
| | Set keySet = map.keySet(); |
| | long[] retval = new long[keySet.size()]; |
| | int i = 0; |
| | for (Iterator iter = keySet.iterator(); iter.hasNext(); i++) { |
| | retval[i] = ((Long)iter.next()).longValue(); |
| | } |
| | return retval; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | public static DataFlavor[] setToSortedDataFlavorArray(Set flavorsSet) { |
| | DataFlavor[] flavors = new DataFlavor[flavorsSet.size()]; |
| | flavorsSet.toArray(flavors); |
| | final Comparator comparator = |
| | new DataFlavorComparator(IndexedComparator.SELECT_WORST); |
| | Arrays.sort(flavors, comparator); |
| | return flavors; |
| | } |
| |
|
| | |
| | |
| | |
| | protected static byte[] inputStreamToByteArray(InputStream str) |
| | throws IOException |
| | { |
| | try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { |
| | int len = 0; |
| | byte[] buf = new byte[8192]; |
| |
|
| | while ((len = str.read(buf)) != -1) { |
| | baos.write(buf, 0, len); |
| | } |
| |
|
| | return baos.toByteArray(); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | public List getPlatformMappingsForNative(String nat) { |
| | return new ArrayList(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | public List getPlatformMappingsForFlavor(DataFlavor df) { |
| | return new ArrayList(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | public abstract static class IndexedComparator implements Comparator { |
| |
|
| | |
| | |
| | |
| | public static final boolean SELECT_BEST = true; |
| |
|
| | |
| | |
| | |
| | public static final boolean SELECT_WORST = false; |
| |
|
| | protected final boolean order; |
| |
|
| | public IndexedComparator() { |
| | this(SELECT_BEST); |
| | } |
| |
|
| | public IndexedComparator(boolean order) { |
| | this.order = order; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | protected static int compareIndices(Map indexMap, |
| | Object obj1, Object obj2, |
| | Integer fallbackIndex) { |
| | Integer index1 = (Integer)indexMap.get(obj1); |
| | Integer index2 = (Integer)indexMap.get(obj2); |
| |
|
| | if (index1 == null) { |
| | index1 = fallbackIndex; |
| | } |
| | if (index2 == null) { |
| | index2 = fallbackIndex; |
| | } |
| |
|
| | return index1.compareTo(index2); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | protected static int compareLongs(Map indexMap, |
| | Object obj1, Object obj2, |
| | Long fallbackIndex) { |
| | Long index1 = (Long)indexMap.get(obj1); |
| | Long index2 = (Long)indexMap.get(obj2); |
| |
|
| | if (index1 == null) { |
| | index1 = fallbackIndex; |
| | } |
| | if (index2 == null) { |
| | index2 = fallbackIndex; |
| | } |
| |
|
| | return index1.compareTo(index2); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public static class CharsetComparator extends IndexedComparator { |
| | private static final Map charsets; |
| | private static String defaultEncoding; |
| |
|
| | private static final Integer DEFAULT_CHARSET_INDEX = Integer.valueOf(2); |
| | private static final Integer OTHER_CHARSET_INDEX = Integer.valueOf(1); |
| | private static final Integer WORST_CHARSET_INDEX = Integer.valueOf(0); |
| | private static final Integer UNSUPPORTED_CHARSET_INDEX = |
| | Integer.valueOf(Integer.MIN_VALUE); |
| |
|
| | private static final String UNSUPPORTED_CHARSET = ""UNSUPPORTED""; |
| |
|
| | static { |
| | HashMap charsetsMap = new HashMap(8, 1.0f); |
| |
|
| | |
| | charsetsMap.put(canonicalName(""UTF-16LE""), Integer.valueOf(4)); |
| | charsetsMap.put(canonicalName(""UTF-16BE""), Integer.valueOf(5)); |
| | charsetsMap.put(canonicalName(""UTF-8""), Integer.valueOf(6)); |
| | charsetsMap.put(canonicalName(""UTF-16""), Integer.valueOf(7)); |
| |
|
| | |
| | charsetsMap.put(canonicalName(""US-ASCII""), WORST_CHARSET_INDEX); |
| |
|
| | String defEncoding = DataTransferer.canonicalName |
| | (DataTransferer.getDefaultTextCharset()); |
| |
|
| | if (charsetsMap.get(defaultEncoding) == null) { |
| | charsetsMap.put(defaultEncoding, DEFAULT_CHARSET_INDEX); |
| | } |
| | charsetsMap.put(UNSUPPORTED_CHARSET, UNSUPPORTED_CHARSET_INDEX); |
| |
|
| | charsets = Collections.unmodifiableMap(charsetsMap); |
| | } |
| |
|
| | public CharsetComparator() { |
| | this(SELECT_BEST); |
| | } |
| |
|
| | public CharsetComparator(boolean order) { |
| | super(order); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public int compare(Object obj1, Object obj2) { |
| | String charset1 = null; |
| | String charset2 = null; |
| | if (order == SELECT_BEST) { |
| | charset1 = (String)obj1; |
| | charset2 = (String)obj2; |
| | } else { |
| | charset1 = (String)obj2; |
| | charset2 = (String)obj1; |
| | } |
| |
|
| | return compareCharsets(charset1, charset2); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | protected int compareCharsets(String charset1, String charset2) { |
| | charset1 = getEncoding(charset1); |
| | charset2 = getEncoding(charset2); |
| |
|
| | int comp = compareIndices(charsets, charset1, charset2, |
| | OTHER_CHARSET_INDEX); |
| |
|
| | if (comp == 0) { |
| | return charset2.compareTo(charset1); |
| | } |
| |
|
| | return comp; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | protected static String getEncoding(String charset) { |
| | if (charset == null) { |
| | return null; |
| | } else if (!DataTransferer.isEncodingSupported(charset)) { |
| | return UNSUPPORTED_CHARSET; |
| | } else { |
| | |
| | |
| | |
| | |
| | String canonicalName = DataTransferer.canonicalName(charset); |
| | return (charsets.containsKey(canonicalName)) |
| | ? canonicalName |
| | : charset; |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public static class DataFlavorComparator extends IndexedComparator { |
| |
|
| | private final CharsetComparator charsetComparator; |
| |
|
| | private static final Map exactTypes; |
| | private static final Map primaryTypes; |
| | private static final Map nonTextRepresentations; |
| | private static final Map textTypes; |
| | private static final Map decodedTextRepresentations; |
| | private static final Map encodedTextRepresentations; |
| |
|
| | private static final Integer UNKNOWN_OBJECT_LOSES = |
| | Integer.valueOf(Integer.MIN_VALUE); |
| | private static final Integer UNKNOWN_OBJECT_WINS = |
| | Integer.valueOf(Integer.MAX_VALUE); |
| |
|
| | private static final Long UNKNOWN_OBJECT_LOSES_L = |
| | Long.valueOf(Long.MIN_VALUE); |
| | private static final Long UNKNOWN_OBJECT_WINS_L = |
| | Long.valueOf(Long.MAX_VALUE); |
| |
|
| | static { |
| | { |
| | HashMap exactTypesMap = new HashMap(4, 1.0f); |
| |
|
| | |
| | exactTypesMap.put(""application/x-java-file-list"", |
| | Integer.valueOf(0)); |
| | exactTypesMap.put(""application/x-java-serialized-object"", |
| | Integer.valueOf(1)); |
| | exactTypesMap.put(""application/x-java-jvm-local-objectref"", |
| | Integer.valueOf(2)); |
| | exactTypesMap.put(""application/x-java-remote-object"", |
| | Integer.valueOf(3)); |
| |
|
| | exactTypes = Collections.unmodifiableMap(exactTypesMap); |
| | } |
| |
|
| | { |
| | HashMap primaryTypesMap = new HashMap(1, 1.0f); |
| |
|
| | primaryTypesMap.put(""application"", Integer.valueOf(0)); |
| |
|
| | primaryTypes = Collections.unmodifiableMap(primaryTypesMap); |
| | } |
| |
|
| | { |
| | HashMap nonTextRepresentationsMap = new HashMap(3, 1.0f); |
| |
|
| | nonTextRepresentationsMap.put(java.io.InputStream.class, |
| | Integer.valueOf(0)); |
| | nonTextRepresentationsMap.put(java.io.Serializable.class, |
| | Integer.valueOf(1)); |
| |
|
| | Class<?> remoteClass = RMI.remoteClass(); |
| | if (remoteClass != null) { |
| | nonTextRepresentationsMap.put(remoteClass, |
| | Integer.valueOf(2)); |
| | } |
| |
|
| | nonTextRepresentations = |
| | Collections.unmodifiableMap(nonTextRepresentationsMap); |
| | } |
| |
|
| | { |
| | HashMap textTypesMap = new HashMap(16, 1.0f); |
| |
|
| | |
| | textTypesMap.put(""text/plain"", Integer.valueOf(0)); |
| |
|
| | |
| | textTypesMap.put(""application/x-java-serialized-object"", |
| | Integer.valueOf(1)); |
| |
|
| | |
| | textTypesMap.put(""text/calendar"", Integer.valueOf(2)); |
| | textTypesMap.put(""text/css"", Integer.valueOf(3)); |
| | textTypesMap.put(""text/directory"", Integer.valueOf(4)); |
| | textTypesMap.put(""text/parityfec"", Integer.valueOf(5)); |
| | textTypesMap.put(""text/rfc822-headers"", Integer.valueOf(6)); |
| | textTypesMap.put(""text/t140"", Integer.valueOf(7)); |
| | textTypesMap.put(""text/tab-separated-values"", Integer.valueOf(8)); |
| | textTypesMap.put(""text/uri-list"", Integer.valueOf(9)); |
| |
|
| | |
| | textTypesMap.put(""text/richtext"", Integer.valueOf(10)); |
| | textTypesMap.put(""text/enriched"", Integer.valueOf(11)); |
| | textTypesMap.put(""text/rtf"", Integer.valueOf(12)); |
| |
|
| | |
| | textTypesMap.put(""text/html"", Integer.valueOf(13)); |
| | textTypesMap.put(""text/xml"", Integer.valueOf(14)); |
| | textTypesMap.put(""text/sgml"", Integer.valueOf(15)); |
| |
|
| | textTypes = Collections.unmodifiableMap(textTypesMap); |
| | } |
| |
|
| | { |
| | HashMap decodedTextRepresentationsMap = new HashMap(4, 1.0f); |
| |
|
| | decodedTextRepresentationsMap.put |
| | (char[].class, Integer.valueOf(0)); |
| | decodedTextRepresentationsMap.put |
| | (java.nio.CharBuffer.class, Integer.valueOf(1)); |
| | decodedTextRepresentationsMap.put |
| | (java.lang.String.class, Integer.valueOf(2)); |
| | decodedTextRepresentationsMap.put |
| | (java.io.Reader.class, Integer.valueOf(3)); |
| |
|
| | decodedTextRepresentations = |
| | Collections.unmodifiableMap(decodedTextRepresentationsMap); |
| | } |
| |
|
| | { |
| | HashMap encodedTextRepresentationsMap = new HashMap(3, 1.0f); |
| |
|
| | encodedTextRepresentationsMap.put |
| | (byte[].class, Integer.valueOf(0)); |
| | encodedTextRepresentationsMap.put |
| | (java.nio.ByteBuffer.class, Integer.valueOf(1)); |
| | encodedTextRepresentationsMap.put |
| | (java.io.InputStream.class, Integer.valueOf(2)); |
| |
|
| | encodedTextRepresentations = |
| | Collections.unmodifiableMap(encodedTextRepresentationsMap); |
| | } |
| | } |
| |
|
| | public DataFlavorComparator() { |
| | this(SELECT_BEST); |
| | } |
| |
|
| | public DataFlavorComparator(boolean order) { |
| | super(order); |
| |
|
| | charsetComparator = new CharsetComparator(order); |
| | } |
| |
|
| | public int compare(Object obj1, Object obj2) { |
| | DataFlavor flavor1 = null; |
| | DataFlavor flavor2 = null; |
| | if (order == SELECT_BEST) { |
| | flavor1 = (DataFlavor)obj1; |
| | flavor2 = (DataFlavor)obj2; |
| | } else { |
| | flavor1 = (DataFlavor)obj2; |
| | flavor2 = (DataFlavor)obj1; |
| | } |
| |
|
| | if (flavor1.equals(flavor2)) { |
| | return 0; |
| | } |
| |
|
| | int comp = 0; |
| |
|
| | String primaryType1 = flavor1.getPrimaryType(); |
| | String subType1 = flavor1.getSubType(); |
| | String mimeType1 = primaryType1 + ""/"" + subType1; |
| | Class class1 = flavor1.getRepresentationClass(); |
| |
|
| | String primaryType2 = flavor2.getPrimaryType(); |
| | String subType2 = flavor2.getSubType(); |
| | String mimeType2 = primaryType2 + ""/"" + subType2; |
| | Class class2 = flavor2.getRepresentationClass(); |
| |
|
| | if (flavor1.isFlavorTextType() && flavor2.isFlavorTextType()) { |
| | |
| | comp = compareIndices(textTypes, mimeType1, mimeType2, |
| | UNKNOWN_OBJECT_LOSES); |
| | if (comp != 0) { |
| | return comp; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | if (doesSubtypeSupportCharset(flavor1)) { |
| | |
| | |
| | comp = compareIndices(decodedTextRepresentations, class1, |
| | class2, UNKNOWN_OBJECT_LOSES); |
| | if (comp != 0) { |
| | return comp; |
| | } |
| |
|
| | |
| | comp = charsetComparator.compareCharsets |
| | (DataTransferer.getTextCharset(flavor1), |
| | DataTransferer.getTextCharset(flavor2)); |
| | if (comp != 0) { |
| | return comp; |
| | } |
| | } |
| |
|
| | |
| | |
| | comp = compareIndices(encodedTextRepresentations, class1, |
| | class2, UNKNOWN_OBJECT_LOSES); |
| | if (comp != 0) { |
| | return comp; |
| | } |
| | } else { |
| | |
| | comp = compareIndices(primaryTypes, primaryType1, primaryType2, |
| | UNKNOWN_OBJECT_LOSES); |
| | if (comp != 0) { |
| | return comp; |
| | } |
| |
|
| | |
| | |
| | |
| | comp = compareIndices(exactTypes, mimeType1, mimeType2, |
| | UNKNOWN_OBJECT_WINS); |
| | if (comp != 0) { |
| | return comp; |
| | } |
| |
|
| | |
| | |
| | comp = compareIndices(nonTextRepresentations, class1, class2, |
| | UNKNOWN_OBJECT_LOSES); |
| | if (comp != 0) { |
| | return comp; |
| | } |
| | } |
| |
|
| | |
| | |
| | return flavor1.getMimeType().compareTo(flavor2.getMimeType()); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public static class IndexOrderComparator extends IndexedComparator { |
| | private final Map indexMap; |
| | private static final Integer FALLBACK_INDEX = |
| | Integer.valueOf(Integer.MIN_VALUE); |
| |
|
| | public IndexOrderComparator(Map indexMap) { |
| | super(SELECT_BEST); |
| | this.indexMap = indexMap; |
| | } |
| |
|
| | public IndexOrderComparator(Map indexMap, boolean order) { |
| | super(order); |
| | this.indexMap = indexMap; |
| | } |
| |
|
| | public int compare(Object obj1, Object obj2) { |
| | if (order == SELECT_WORST) { |
| | return -compareIndices(indexMap, obj1, obj2, FALLBACK_INDEX); |
| | } else { |
| | return compareIndices(indexMap, obj1, obj2, FALLBACK_INDEX); |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | private static class RMI { |
| | private static final Class<?> remoteClass = getClass(""java.rmi.Remote""); |
| | private static final Class<?> marshallObjectClass = |
| | getClass(""java.rmi.MarshalledObject""); |
| | private static final Constructor<?> marshallCtor = |
| | getConstructor(marshallObjectClass, Object.class); |
| | private static final Method marshallGet = |
| | getMethod(marshallObjectClass, ""get""); |
| |
|
| | private static Class<?> getClass(String name) { |
| | try { |
| | return Class.forName(name, true, null); |
| | } catch (ClassNotFoundException e) { |
| | return null; |
| | } |
| | } |
| |
|
| | private static Constructor<?> getConstructor(Class<?> c, Class<?>... types) { |
| | try { |
| | return (c == null) ? null : c.getDeclaredConstructor(types); |
| | } catch (NoSuchMethodException x) { |
| | throw new AssertionError(x); |
| | } |
| | } |
| |
|
| | private static Method getMethod(Class<?> c, String name, Class<?>... types) { |
| | try { |
| | return (c == null) ? null : c.getMethod(name, types); |
| | } catch (NoSuchMethodException e) { |
| | throw new AssertionError(e); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | static boolean isRemote(Class<?> c) { |
| | return (remoteClass == null) ? null : remoteClass.isAssignableFrom(c); |
| | } |
| |
|
| | |
| | |
| | |
| | static Class<?> remoteClass() { |
| | return remoteClass; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | static Object newMarshalledObject(Object obj) throws IOException { |
| | try { |
| | return marshallCtor.newInstance(obj); |
| | } catch (InstantiationException x) { |
| | throw new AssertionError(x); |
| | } catch (IllegalAccessException x) { |
| | throw new AssertionError(x); |
| | } catch (InvocationTargetException x) { |
| | Throwable cause = x.getCause(); |
| | if (cause instanceof IOException) |
| | throw (IOException)cause; |
| | throw new AssertionError(x); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | static Object getMarshalledObject(Object obj) |
| | throws IOException, ClassNotFoundException |
| | { |
| | try { |
| | return marshallGet.invoke(obj); |
| | } catch (IllegalAccessException x) { |
| | throw new AssertionError(x); |
| | } catch (InvocationTargetException x) { |
| | Throwable cause = x.getCause(); |
| | if (cause instanceof IOException) |
| | throw (IOException)cause; |
| | if (cause instanceof ClassNotFoundException) |
| | throw (ClassNotFoundException)cause; |
| | throw new AssertionError(x); |
| | } |
| | } |
| | } |
| | } |
| | ",koutheir/incinerator-hotspot,jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java,Java,gpl-2.0,117504 |
| | 4," |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | package org.eclipse.che.account.api; |
| |
|
| | import com.google.inject.AbstractModule; |
| | import org.eclipse.che.account.spi.AccountDao; |
| | import org.eclipse.che.account.spi.jpa.JpaAccountDao; |
| |
|
| | |
| | public class AccountModule extends AbstractModule { |
| | @Override |
| | protected void configure() { |
| | bind(AccountDao.class).to(JpaAccountDao.class); |
| | } |
| | } |
| | ",sleshchenko/che,wsmaster/che-core-api-account/src/main/java/org/eclipse/che/account/api/AccountModule.java,Java,epl-1.0,732 |
| | 5,"#!/usr/bin/env python2.5 |
| | # |
| | # Copyright 2009 the Melange authors. |
| | # |
| | # Licensed 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: |
| | # |
| | # 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. |
| |
|
| | """"""GHOPTask (Model) query functions. |
| | """""" |
| |
|
| | __authors__ = [ |
| | '""Madhusudan.C.S"" <madhusudancs@gmail.com>', |
| | '""Daniel Hans"" <daniel.m.hans@gmail.com>', |
| | '""Lennard de Rijk"" <ljvderijk@gmail.com>', |
| | ] |
| |
|
| |
|
| | import datetime |
| |
|
| | from google.appengine.ext import db |
| |
|
| | from django.utils import simplejson |
| | from django.utils.translation import ugettext |
| |
|
| | from soc.logic.models import base |
| | from soc.logic import tags |
| |
|
| | from soc.modules.ghop.logic.models import comment as ghop_comment_logic |
| |
|
| | import soc.models.linkable |
| |
|
| | import soc.modules.ghop.logic.models.organization |
| | import soc.modules.ghop.models.task |
| |
|
| |
|
| | STATE_TRANSITIONS = { |
| | 'Claimed': 'transitFromClaimed', |
| | 'NeedsReview': 'transitFromNeedsReview', |
| | 'ActionNeeded': 'transitFromActionNeeded', |
| | 'NeedsWork': 'transitFromNeedsWork', |
| | } |
| |
|
| | TAG_NAMES = ['arbit_tag', 'difficulty', 'task_type'] |
| |
|
| | class Logic(base.Logic): |
| | """"""Logic methods for the GHOPTask model. |
| | """""" |
| |
|
| | DEF_ACTION_NEEDED_MSG = ugettext( |
| | '(The Melange Automated System has detected that the intial ' |
| | 'deadline has been passed and it has set the task status to ' |
| | 'ActionNeeded.)') |
| |
|
| | DEF_NO_MORE_WORK_MSG = ugettext( |
| | '(The Melange Automated System has detected that the deadline ' |
| | 'has been passed and no more work can be submitted.)') |
| |
|
| | DEF_REOPENED_MSG = ugettext( |
| | '(The Melange Automated System has detected that the final ' |
| | 'deadline has been passed and it has Reopened the task.)') |
| |
|
| |
|
| | def __init__(self, model=soc.modules.ghop.models.task.GHOPTask, |
| | base_model=soc.models.linkable.Linkable, |
| | scope_logic=soc.modules.ghop.logic.models.organization): |
| | """"""Defines the name, key_name and model for this entity. |
| | """""" |
| |
|
| | self.tags_service = tags.TagsService(TAG_NAMES) |
| |
|
| | super(Logic, self).__init__(model, base_model=base_model, |
| | scope_logic=scope_logic) |
| |
|
| | def updateEntityProperties(self, entity, entity_properties, |
| | silent=False, store=True): |
| | """"""See base.Logic.updateEntityProperties(). |
| |
|
| | Also ensures that the history property of the task is updated in the same |
| | datastore operation. |
| | """""" |
| |
|
| | # TODO: History needs a proper test drive and perhaps a refactoring |
| | history = {} |
| |
|
| | # we construct initial snapshot of the task when it is published |
| | # for the first time. |
| | if entity_properties and 'status' in entity_properties: |
| | if entity.status == 'Unpublished' or entity.status == 'Unapproved': |
| | if entity_properties['status'] == 'Open': |
| | history = { |
| | 'title': entity.title, |
| | 'description': entity.description, |
| | 'difficulty': entity.difficulty[0].tag, |
| | 'task_type': [type.tag for type in entity.task_type], |
| | 'time_to_complete': entity.time_to_complete, |
| | 'mentors': [m_key.name() for m_key in entity.mentors], |
| | 'user': '', |
| | 'student': '', |
| | 'status': entity.status, |
| | 'deadline': '', |
| | 'created_by': entity.created_by.key().name(), |
| | 'created_on': str(entity.created_on), |
| | 'modified_on': str(entity.modified_on), |
| | } |
| |
|
| | if entity.modified_by: |
| | history['modified_by'] = entity.modified_by.key().name() |
| |
|
| | # initialize history |
| | task_history = {} |
| | # extract the existing json history from the entity to update it |
| | elif entity.history: |
| | task_history = simplejson.loads(entity.history) |
| | else: |
| | task_history = {} |
| |
|
| | # we construct history for only changed entity properties |
| | if entity_properties: |
| | for property in entity_properties: |
| | changed_val = getattr(entity, property) |
| | if changed_val != entity_properties[property]: |
| | if property == 'deadline': |
| | history[property] = str(changed_val) |
| | else: |
| | history[property] = changed_val |
| |
|
| | if history: |
| | # create a dictionary for the new history update with timestamp as key |
| | tstamp = str(datetime.datetime.now()) |
| | new_history = {tstamp: history} |
| |
|
| | # update existing history |
| | task_history.update(new_history) |
| | task_history_str = simplejson.dumps(task_history) |
| |
|
| | # update the task's history property |
| | history_property = { |
| | 'history': task_history_str |
| | } |
| | entity_properties.update(history_property) |
| |
|
| | entity = self.tags_service.setTagValuesForEntity(entity, entity_properties) |
| |
|
| | # call the base logic method to store the updated Task entity |
| | return super(Logic, self).updateEntityProperties( |
| | entity, entity_properties, silent=silent, store=store) |
| |
|
| | def updateEntityPropertiesWithCWS(self, entity, entity_properties, |
| | comment_properties=None, |
| | ws_properties=None, silent=False): |
| | """"""Updates the GHOPTask entity properties and creates a comment |
| | entity. |
| |
|
| | Args: |
| | entity: a model entity |
| | entity_properties: keyword arguments that correspond to entity |
| | properties and their values |
| | comment_properties: keyword arguments that correspond to the |
| | GHOPTask's to be created comment entity |
| | silent: iff True does not call post store methods. |
| | """""" |
| |
|
| | # pylint: disable-msg=W0621 |
| | from soc.modules.ghop.logic.models.comment import logic as \ |
| | ghop_comment_logic |
| | from soc.modules.ghop.logic.models.work_submission import logic as \ |
| | ghop_work_submission_logic |
| | from soc.modules.ghop.models import comment as ghop_comment_model |
| | from soc.modules.ghop.models import work_submission as \ |
| | ghop_work_submission_model |
| |
|
| | if entity_properties: |
| | entity = self.updateEntityProperties(entity, entity_properties, |
| | silent=silent, store=False) |
| |
|
| | comment_entity = ghop_comment_model.GHOPComment(**comment_properties) |
| |
|
| | ws_entity = None |
| | if ws_properties: |
| | ws_entity = ghop_work_submission_model.GHOPWorkSubmission( |
| | |
| |
|
| | def comment_create(): |
| | """"""Method to be run in transaction that stores Task, Comment and |
| | WorkSubmission. |
| | """""" |
| | entity.put() |
| | if ws_entity: |
| | ws_entity.put() |
| | comment_entity.content = comment_entity.content % ( |
| | ws_entity.key().id_or_name()) |
| | comment_entity.put() |
| | return entity, comment_entity, ws_entity |
| | else: |
| | comment_entity.put() |
| | return entity, comment_entity, None |
| |
|
| | entity, comment_entity, ws_entity = db.run_in_transaction( |
| | comment_create) |
| |
|
| | if not silent: |
| | # call the _onCreate methods for the Comment and WorkSubmission |
| | if comment_entity: |
| | ghop_comment_logic._onCreate(comment_entity) |
| |
|
| | if ws_entity: |
| | ghop_work_submission_logic._onCreate(ws_entity) |
| |
|
| | return entity, comment_entity, ws_entity |
| |
|
| | def updateOrCreateFromFields(self, properties, silent=False): |
| | """"""See base.Logic.updateOrCreateFromFields(). |
| | """""" |
| |
|
| | # TODO: History needs to be tested and perhaps refactored |
| | if properties.get('status') == 'Open': |
| | history = { |
| | 'title': properties['title'], |
| | 'description': properties['description'], |
| | 'difficulty': properties['difficulty']['tags'], |
| | 'task_type': properties['type_tags'], |
| | 'time_to_complete': properties['time_to_complete'], |
| | 'mentors': [m_key.name() for m_key in properties['mentors']], |
| | 'user': '', |
| | 'student': '', |
| | 'status': properties['status'], |
| | 'deadline': '', |
| | 'created_on': str(properties['created_on']), |
| | 'modified_on': str(properties['modified_on']), |
| | } |
| |
|
| | if 'created_by' in properties and properties['created_by']: |
| | history['created_by'] = properties['created_by'].key().name() |
| | history['modified_by'] = properties['modified_by'].key().name() |
| |
|
| | # Constructs new history from the _constructNewHistory method, assigns |
| | # it as a value to the dictionary key with current timestamp and dumps |
| | # a JSON string. |
| | task_history_str = simplejson.dumps({ |
| | str(datetime.datetime.now()): history, |
| | }) |
| |
|
| | # update the task's history property |
| | history_property = { |
| | 'history': task_history_str |
| | } |
| | properties.update(history_property) |
| |
|
| | entity = super(Logic, self).updateOrCreateFromFields(properties, silent) |
| |
|
| | self.tags_service.setTagValuesForEntity(entity, properties) |
| |
|
| | return entity |
| |
|
| | def getFromKeyFieldsWithCWSOr404(self, fields): |
| | """"""Returns the Task, all Comments and all WorkSubmissions for the Task |
| | specified by the fields argument. |
| |
|
| | For args see base.getFromKeyFieldsOr404(). |
| | """""" |
| |
|
| | # pylint: disable-msg=W0621 |
| | from soc.modules.ghop.logic.models.comment import logic as \ |
| | ghop_comment_logic |
| | from soc.modules.ghop.logic.models.work_submission import logic as \ |
| | ghop_work_submission_logic |
| | |
| | entity = self.getFromKeyFieldsOr404(fields) |
| |
|
| | comment_entities = ghop_comment_logic.getForFields( |
| | ancestors=[entity], order=['created_on']) |
| |
|
| | ws_entities = ghop_work_submission_logic.getForFields( |
| | ancestors=[entity], order=['submitted_on']) |
| |
|
| | return entity, comment_entities, ws_entities |
| |
|
| | def updateTaskStatus(self, entity): |
| | """"""Method used to transit a task from a state to another state |
| | depending on the context. Whenever the deadline has passed. |
| |
|
| | Args: |
| | entity: The GHOPTask entity |
| |
|
| | Returns: |
| | Task entity and a Comment entity if the occurring transit created one. |
| | """""" |
| |
|
| | from soc.modules.ghop.tasks import task_update |
| |
|
| | if entity.deadline and datetime.datetime.now() > entity.deadline: |
| | # calls a specific method to make a transition depending on the |
| | # task's current state |
| | transit_func = getattr(self, STATE_TRANSITIONS[entity.status]) |
| | update_dict = transit_func(entity) |
| |
|
| | comment_properties = { |
| | 'parent': entity, |
| | 'scope_path': entity.key().name(), |
| | 'created_by': None, |
| | 'content': update_dict['content'], |
| | 'changes': update_dict['changes'], |
| | } |
| |
|
| | entity, comment_entity, _ = self.updateEntityPropertiesWithCWS( |
| | entity, update_dict['properties'], comment_properties) |
| |
|
| | if entity.deadline: |
| | # only if there is a deadline set we should schedule another task |
| | task_update.spawnUpdateTask(entity) |
| | else: |
| | comment_entity = None |
| |
|
| | return entity, comment_entity |
| |
|
| | def transitFromClaimed(self, entity): |
| | """"""Makes a state transition of a GHOP Task from Claimed state |
| | to a relevant state. |
| |
|
| | Args: |
| | entity: The GHOPTask entity |
| | """""" |
| |
|
| | # deadline is extended by 24 hours. |
| | deadline = entity.deadline + datetime.timedelta( |
| | hours=24) |
| |
|
| | properties = { |
| | 'status': 'ActionNeeded', |
| | 'deadline': deadline, |
| | } |
| |
|
| | changes = [ugettext('User-MelangeAutomatic'), |
| | ugettext('Action-Warned for action'), |
| | ugettext('Status-%s' % (properties['status']))] |
| |
|
| | content = self.DEF_ACTION_NEEDED_MSG |
| |
|
| | update_dict = { |
| | 'properties': properties, |
| | 'changes': changes, |
| | 'content': content, |
| | } |
| |
|
| | return update_dict |
| |
|
| | def transitFromNeedsReview(self, entity): |
| | """"""Makes a state transition of a GHOP Task from NeedsReview state |
| | to a relevant state. |
| |
|
| | Args: |
| | entity: The GHOPTask entity |
| | """""" |
| |
|
| | properties = { |
| | 'deadline': None, |
| | } |
| |
|
| | changes = [ugettext('User-MelangeAutomatic'), |
| | ugettext('Action-Deadline passed'), |
| | ugettext('Status-%s' % (entity.status))] |
| |
|
| | content = self.DEF_NO_MORE_WORK_MSG |
| |
|
| | update_dict = { |
| | 'properties': properties, |
| | 'changes': changes, |
| | 'content': content, |
| | } |
| |
|
| | return update_dict |
| |
|
| | def transitFromActionNeeded(self, entity): |
| | """"""Makes a state transition of a GHOP Task from ActionNeeded state |
| | to a relevant state. |
| |
|
| | Args: |
| | entity: The GHOPTask entity |
| | """""" |
| |
|
| | properties = { |
| | 'user': None, |
| | 'student': None, |
| | 'status': 'Reopened', |
| | 'deadline': None, |
| | } |
| |
|
| | changes = [ugettext('User-MelangeAutomatic'), |
| | ugettext('Action-Forcibly reopened'), |
| | ugettext('Status-Reopened')] |
| |
|
| | content = self.DEF_REOPENED_MSG |
| |
|
| | update_dict = { |
| | 'properties': properties, |
| | 'changes': changes, |
| | 'content': content, |
| | } |
| |
|
| | return update_dict |
| |
|
| | def transitFromNeedsWork(self, entity): |
| | """"""Makes a state transition of a GHOP Task from NeedsWork state |
| | to a relevant state. |
| |
|
| | Args: |
| | entity: The GHOPTask entity |
| | """""" |
| |
|
| | properties = { |
| | 'user': None, |
| | 'student': None, |
| | 'status': 'Reopened', |
| | 'deadline': None, |
| | } |
| |
|
| | changes = [ugettext('User-MelangeAutomatic'), |
| | ugettext('Action-Forcibly reopened'), |
| | ugettext('Status-Reopened')] |
| | |
| | update_dict = { |
| | 'properties': properties, |
| | 'changes': changes, |
| | 'content': None, |
| | } |
| |
|
| | return update_dict |
| |
|
| | def delete(self, entity): |
| | """"""Delete existing entity from datastore. |
| | """""" |
| | |
| | def task_delete_txn(entity): |
| | """"""Performs all necessary operations in a single transaction when a task |
| | is deleted. |
| | """""" |
| |
|
| | to_delete = [] |
| | to_delete += ghop_comment_logic.logic.getForFields(ancestors=[entity]) |
| | to_delete += [entity] |
| | |
| | db.delete(to_delete) |
| | |
| | self.tags_service.removeAllTagsForEntity(entity) |
| | db.run_in_transaction(task_delete_txn, entity) |
| |
|
| |
|
| | logic = Logic() |
| | ",MatthewWilkes/mw4068-packaging,src/melange/src/soc/modules/ghop/logic/models/task.py,Python,apache-2.0,14298 |
| | 6," |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #ifndef _DEFS_H |
| | #define _DEFS_H |
| |
|
| | #define RELEASE ""1.5.1"" |
| |
|
| | #ifdef __WIN32__ |
| | typedef char bool; |
| | enum { |
| | true=1, |
| | false=0 |
| | }; |
| | #else |
| | #include <stdbool.h> |
| | #endif |
| |
|
| | #define NETWORK_DEFAULT_PORTNUM (49000) |
| | #define NETSIZE_MIN (15) |
| | #define NETSIZE_MAX (28) |
| | #define NETWORK_CHUNK_SIZE (1<<NETSIZE_MIN) |
| |
|
| | #ifndef __arm__ |
| | #define DOING_LODS |
| | #endif |
| |
|
| | extern int Reader (void *ptr, unsigned long size, unsigned long loops); |
| |
|
| | extern int ReaderLODSQ (void *ptr, unsigned long size, unsigned long loops); |
| | extern int ReaderLODSD (void *ptr, unsigned long size, unsigned long loops); |
| | extern int ReaderLODSW (void *ptr, unsigned long size, unsigned long loops); |
| | extern int ReaderLODSB (void *ptr, unsigned long size, unsigned long loops); |
| |
|
| | extern int Reader_128bytes (void *ptr, unsigned long size, unsigned long loops); |
| | extern int RandomReader (void *ptr, unsigned long n_chunks, unsigned long loops); |
| |
|
| | extern int Writer (void *ptr, unsigned long size, unsigned long loops, unsigned long value); |
| | extern int Writer_128bytes (void *ptr, unsigned long size, unsigned long loops, unsigned long value); |
| | extern int RandomWriter (void *ptr, unsigned long size, unsigned long loops, unsigned long value); |
| |
|
| | extern int RegisterToRegister (unsigned long); |
| |
|
| | extern int StackReader (unsigned long); |
| | extern int StackWriter (unsigned long); |
| |
|
| | extern int RegisterToVector (unsigned long); |
| | extern int Register8ToVector (unsigned long); |
| | extern int Register16ToVector (unsigned long); |
| | extern int Register32ToVector (unsigned long); |
| | extern int Register64ToVector (unsigned long); |
| |
|
| | extern int VectorToVector (unsigned long); |
| |
|
| | extern int VectorToVectorAVX (unsigned long); |
| |
|
| | extern int VectorToRegister (unsigned long); |
| | extern int Vector8ToRegister (unsigned long); |
| | extern int Vector16ToRegister (unsigned long); |
| | extern int Vector32ToRegister (unsigned long); |
| | extern int Vector64ToRegister (unsigned long); |
| |
|
| | extern int Copy (void*, void*, unsigned long, unsigned long); |
| | extern int CopySSE (void*, void*, unsigned long, unsigned long); |
| | extern int CopyAVX (void*, void*, unsigned long, unsigned long); |
| | extern int CopySSE_128bytes (void*, void*, unsigned long, unsigned long); |
| |
|
| | extern int ReaderAVX (void *ptr, unsigned long, unsigned long); |
| | extern int RandomReaderAVX (void *ptr, unsigned long, unsigned long); |
| |
|
| | extern int ReaderSSE2 (void *ptr, unsigned long, unsigned long); |
| | extern int ReaderSSE2_bypass (void *ptr, unsigned long, unsigned long); |
| | extern int RandomReaderSSE2 (unsigned long **ptr, unsigned long, unsigned long); |
| | extern int RandomReaderSSE2_bypass (unsigned long **ptr, unsigned long, unsigned long); |
| |
|
| | extern int WriterAVX (void *ptr, unsigned long, unsigned long, unsigned long); |
| | extern int RandomWriterAVX (void *ptr, unsigned long, unsigned long, unsigned long); |
| |
|
| | extern int WriterSSE2 (void *ptr, unsigned long, unsigned long, unsigned long); |
| | extern int RandomWriterSSE2(unsigned long **ptr, unsigned long, unsigned long, unsigned long); |
| |
|
| | extern int ReaderSSE2_128bytes(void *ptr, unsigned long, unsigned long); |
| | extern int WriterSSE2_128bytes(void *ptr, unsigned long, unsigned long, unsigned long); |
| |
|
| | extern int ReaderSSE2_128bytes_bypass (void *ptr, unsigned long, unsigned long); |
| | extern int WriterSSE2_128bytes_bypass (void *ptr, unsigned long, unsigned long, unsigned long); |
| |
|
| | extern int WriterAVX_bypass (void *ptr, unsigned long, unsigned long, unsigned long); |
| | extern int WriterSSE2_bypass (void *ptr, unsigned long, unsigned long, unsigned long); |
| | extern int RandomWriterSSE2_bypass (unsigned long **ptr, unsigned long, unsigned long, unsigned long); |
| |
|
| | extern void IncrementRegisters (unsigned long count); |
| | extern void IncrementStack (unsigned long count); |
| |
|
| | extern void get_cpuid_family (char *family_return); |
| | extern void get_cpuid_cache_info (uint32_t *array, int index); |
| | extern unsigned get_cpuid1_ecx (); |
| | extern unsigned get_cpuid1_edx (); |
| | extern unsigned get_cpuid7_ebx (); |
| | extern unsigned get_cpuid_80000001_ecx (); |
| | extern unsigned get_cpuid_80000001_edx (); |
| |
|
| | #define CPUID_EDX_MMX (1<<23) |
| | #define CPUID_EDX_SSE (1<<25) |
| | #define CPUID_EDX_SSE2 (1<<26) |
| | #define CPUID_EDX_INTEL64 (1<<29) |
| | #define CPUID_EDX_XD (1<<20) |
| | #define CPUID_ECX_SSE3 (1) |
| | #define CPUID_ECX_SSSE3 (1<<9) |
| | #define CPUID_ECX_SSE4A (1<<6) |
| | #define CPUID_ECX_SSE41 (1<<19) |
| | #define CPUID_ECX_SSE42 (1<<20) |
| | #define CPUID_ECX_AES (1<<25) |
| | #define CPUID_ECX_AVX (1<<28) |
| | #define CPUID_EBX_AVX2 (0x20) |
| |
|
| | #define FBLOOPS_R 400 |
| | #define FBLOOPS_W 800 |
| | #define FB_SIZE (640*480*2) |
| |
|
| | #endif |
| |
|
| | ",X0rg/CPU-X,src/bandwidth/defs.h,C,gpl-3.0,7212 |
| | 7,"# browsershots.org - Test your web design in different browsers |
| | # Copyright (C) 2007 Johann C. Rocholl <johann@browsershots.org> |
| | # |
| | # Browsershots is free software; you can redistribute it and/or modify |
| | # it under the terms of the GNU General Public License as published by |
| | # the Free Software Foundation; either version 3 of the License, or |
| | # (at your option) any later version. |
| | # |
| | # Browsershots 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 |
| | # General Public License for more details. |
| | # |
| | # You should have received a copy of the GNU General Public License |
| | # along with this program. If not, see <http: |
| |
|
| | """""" |
| | GUI-specific interface functions for X11. |
| | """""" |
| |
|
| | __revision__ = ""$Rev: 2248 $"" |
| | __date__ = ""$Date: 2007-10-26 15:46:36 +0530 (Fri, 26 Oct 2007) $"" |
| | __author__ = ""$Author: johann $"" |
| |
|
| |
|
| | from shotfactory04.gui.linux import firefox as base |
| |
|
| |
|
| | class Gui(base.Gui): |
| | """""" |
| | Special functions for Mozilla Bon Echo. |
| | """""" |
| | pass |
| | ",mintuhouse/shotfactory,shotfactory04/gui/linux/bonecho.py,Python,gpl-3.0,1091 |
| | 8,"
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | package ims.careuk.vo;
|
| |
|
| | import java.util.ArrayList;
|
| | import java.util.Collections;
|
| | import java.util.Comparator;
|
| | import java.util.Iterator;
|
| | import ims.framework.enumerations.SortOrder;
|
| |
|
| | |
| | |
| |
|
| | public class TCIOutcomeForAppointmentDNAVoCollection extends ims.vo.ValueObjectCollection implements ims.vo.ImsCloneable, Iterable<TCIOutcomeForAppointmentDNAVo>
|
| | {
|
| | private static final long serialVersionUID = 1L;
|
| |
|
| | private ArrayList<TCIOutcomeForAppointmentDNAVo> col = new ArrayList<TCIOutcomeForAppointmentDNAVo>();
|
| | public String getBoClassName()
|
| | {
|
| | return ""ims.careuk.domain.objects.TCIOutcomeForPatientElectiveList"";
|
| | }
|
| | public boolean add(TCIOutcomeForAppointmentDNAVo value)
|
| | {
|
| | if(value == null)
|
| | return false;
|
| | if(this.col.indexOf(value) < 0)
|
| | {
|
| | return this.col.add(value);
|
| | }
|
| | return false;
|
| | }
|
| | public boolean add(int index, TCIOutcomeForAppointmentDNAVo value)
|
| | {
|
| | if(value == null)
|
| | return false;
|
| | if(this.col.indexOf(value) < 0)
|
| | {
|
| | this.col.add(index, value);
|
| | return true;
|
| | }
|
| | return false;
|
| | }
|
| | public void clear()
|
| | {
|
| | this.col.clear();
|
| | }
|
| | public void remove(int index)
|
| | {
|
| | this.col.remove(index);
|
| | }
|
| | public int size()
|
| | {
|
| | return this.col.size();
|
| | }
|
| | public int indexOf(TCIOutcomeForAppointmentDNAVo instance)
|
| | {
|
| | return col.indexOf(instance);
|
| | }
|
| | public TCIOutcomeForAppointmentDNAVo get(int index)
|
| | {
|
| | return this.col.get(index);
|
| | }
|
| | public boolean set(int index, TCIOutcomeForAppointmentDNAVo value)
|
| | {
|
| | if(value == null)
|
| | return false;
|
| | this.col.set(index, value);
|
| | return true;
|
| | }
|
| | public void remove(TCIOutcomeForAppointmentDNAVo instance)
|
| | {
|
| | if(instance != null)
|
| | {
|
| | int index = indexOf(instance);
|
| | if(index >= 0)
|
| | remove(index);
|
| | }
|
| | }
|
| | public boolean contains(TCIOutcomeForAppointmentDNAVo instance)
|
| | {
|
| | return indexOf(instance) >= 0;
|
| | }
|
| | public Object clone()
|
| | {
|
| | TCIOutcomeForAppointmentDNAVoCollection clone = new TCIOutcomeForAppointmentDNAVoCollection();
|
| |
|
| | for(int x = 0; x < this.col.size(); x++)
|
| | {
|
| | if(this.col.get(x) != null)
|
| | clone.col.add((TCIOutcomeForAppointmentDNAVo)this.col.get(x).clone());
|
| | else
|
| | clone.col.add(null);
|
| | }
|
| |
|
| | return clone;
|
| | }
|
| | public boolean isValidated()
|
| | {
|
| | for(int x = 0; x < col.size(); x++)
|
| | if(!this.col.get(x).isValidated())
|
| | return false;
|
| | return true;
|
| | }
|
| | public String[] validate()
|
| | {
|
| | return validate(null);
|
| | }
|
| | public String[] validate(String[] existingErrors)
|
| | {
|
| | if(col.size() == 0)
|
| | return null;
|
| | java.util.ArrayList<String> listOfErrors = new java.util.ArrayList<String>();
|
| | if(existingErrors != null)
|
| | {
|
| | for(int x = 0; x < existingErrors.length; x++)
|
| | {
|
| | listOfErrors.add(existingErrors[x]);
|
| | }
|
| | }
|
| | for(int x = 0; x < col.size(); x++)
|
| | {
|
| | String[] listOfOtherErrors = this.col.get(x).validate();
|
| | if(listOfOtherErrors != null)
|
| | {
|
| | for(int y = 0; y < listOfOtherErrors.length; y++)
|
| | {
|
| | listOfErrors.add(listOfOtherErrors[y]);
|
| | }
|
| | }
|
| | }
|
| |
|
| | int errorCount = listOfErrors.size();
|
| | if(errorCount == 0)
|
| | return null;
|
| | String[] result = new String[errorCount];
|
| | for(int x = 0; x < errorCount; x++)
|
| | result[x] = (String)listOfErrors.get(x);
|
| | return result;
|
| | }
|
| | public TCIOutcomeForAppointmentDNAVoCollection sort()
|
| | {
|
| | return sort(SortOrder.ASCENDING);
|
| | }
|
| | public TCIOutcomeForAppointmentDNAVoCollection sort(boolean caseInsensitive)
|
| | {
|
| | return sort(SortOrder.ASCENDING, caseInsensitive);
|
| | }
|
| | public TCIOutcomeForAppointmentDNAVoCollection sort(SortOrder order)
|
| | {
|
| | return sort(new TCIOutcomeForAppointmentDNAVoComparator(order));
|
| | }
|
| | public TCIOutcomeForAppointmentDNAVoCollection sort(SortOrder order, boolean caseInsensitive)
|
| | {
|
| | return sort(new TCIOutcomeForAppointmentDNAVoComparator(order, caseInsensitive));
|
| | }
|
| | @SuppressWarnings(""unchecked"")
|
| | public TCIOutcomeForAppointmentDNAVoCollection sort(Comparator comparator)
|
| | {
|
| | Collections.sort(col, comparator);
|
| | return this;
|
| | }
|
| | public ims.careuk.vo.TCIOutcomeForPatientElectiveListRefVoCollection toRefVoCollection()
|
| | {
|
| | ims.careuk.vo.TCIOutcomeForPatientElectiveListRefVoCollection result = new ims.careuk.vo.TCIOutcomeForPatientElectiveListRefVoCollection();
|
| | for(int x = 0; x < this.col.size(); x++)
|
| | {
|
| | result.add(this.col.get(x));
|
| | }
|
| | return result;
|
| | }
|
| | public TCIOutcomeForAppointmentDNAVo[] toArray()
|
| | {
|
| | TCIOutcomeForAppointmentDNAVo[] arr = new TCIOutcomeForAppointmentDNAVo[col.size()];
|
| | col.toArray(arr);
|
| | return arr;
|
| | }
|
| | public Iterator<TCIOutcomeForAppointmentDNAVo> iterator()
|
| | {
|
| | return col.iterator();
|
| | }
|
| | @Override
|
| | protected ArrayList getTypedCollection()
|
| | {
|
| | return col;
|
| | }
|
| | private class TCIOutcomeForAppointmentDNAVoComparator implements Comparator
|
| | {
|
| | private int direction = 1;
|
| | private boolean caseInsensitive = true;
|
| | public TCIOutcomeForAppointmentDNAVoComparator()
|
| | {
|
| | this(SortOrder.ASCENDING);
|
| | }
|
| | public TCIOutcomeForAppointmentDNAVoComparator(SortOrder order)
|
| | {
|
| | if (order == SortOrder.DESCENDING)
|
| | {
|
| | direction = -1;
|
| | }
|
| | }
|
| | public TCIOutcomeForAppointmentDNAVoComparator(SortOrder order, boolean caseInsensitive)
|
| | {
|
| | if (order == SortOrder.DESCENDING)
|
| | {
|
| | direction = -1;
|
| | }
|
| | this.caseInsensitive = caseInsensitive;
|
| | }
|
| | public int compare(Object obj1, Object obj2)
|
| | {
|
| | TCIOutcomeForAppointmentDNAVo voObj1 = (TCIOutcomeForAppointmentDNAVo)obj1;
|
| | TCIOutcomeForAppointmentDNAVo voObj2 = (TCIOutcomeForAppointmentDNAVo)obj2;
|
| | return direction*(voObj1.compareTo(voObj2, this.caseInsensitive));
|
| | }
|
| | public boolean equals(Object obj)
|
| | {
|
| | return false;
|
| | }
|
| | }
|
| | public ims.careuk.vo.beans.TCIOutcomeForAppointmentDNAVoBean[] getBeanCollection()
|
| | {
|
| | return getBeanCollectionArray();
|
| | }
|
| | public ims.careuk.vo.beans.TCIOutcomeForAppointmentDNAVoBean[] getBeanCollectionArray()
|
| | {
|
| | ims.careuk.vo.beans.TCIOutcomeForAppointmentDNAVoBean[] result = new ims.careuk.vo.beans.TCIOutcomeForAppointmentDNAVoBean[col.size()];
|
| | for(int i = 0; i < col.size(); i++)
|
| | {
|
| | TCIOutcomeForAppointmentDNAVo vo = ((TCIOutcomeForAppointmentDNAVo)col.get(i));
|
| | result[i] = (ims.careuk.vo.beans.TCIOutcomeForAppointmentDNAVoBean)vo.getBean();
|
| | }
|
| | return result;
|
| | }
|
| | public static TCIOutcomeForAppointmentDNAVoCollection buildFromBeanCollection(java.util.Collection beans)
|
| | {
|
| | TCIOutcomeForAppointmentDNAVoCollection coll = new TCIOutcomeForAppointmentDNAVoCollection();
|
| | if(beans == null)
|
| | return coll;
|
| | java.util.Iterator iter = beans.iterator();
|
| | while (iter.hasNext())
|
| | {
|
| | coll.add(((ims.careuk.vo.beans.TCIOutcomeForAppointmentDNAVoBean)iter.next()).buildVo());
|
| | }
|
| | return coll;
|
| | }
|
| | public static TCIOutcomeForAppointmentDNAVoCollection buildFromBeanCollection(ims.careuk.vo.beans.TCIOutcomeForAppointmentDNAVoBean[] beans)
|
| | {
|
| | TCIOutcomeForAppointmentDNAVoCollection coll = new TCIOutcomeForAppointmentDNAVoCollection();
|
| | if(beans == null)
|
| | return coll;
|
| | for(int x = 0; x < beans.length; x++)
|
| | {
|
| | coll.add(beans[x].buildVo());
|
| | }
|
| | return coll;
|
| | }
|
| | }
|
| | ",open-health-hub/openmaxims-linux,openmaxims_workspace/ValueObjects/src/ims/careuk/vo/TCIOutcomeForAppointmentDNAVoCollection.java,Java,agpl-3.0,8921 |
| | 9," |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include ""der_locl.h"" |
| |
|
| | RCSID(""$Id: der_copy.c,v 1.1.1.1 2011/06/10 09:34:42 andrew Exp $""); |
| |
|
| | int |
| | der_copy_general_string (const heim_general_string *from, |
| | heim_general_string *to) |
| | { |
| | |
| | if(*to == NULL) |
| | return ENOMEM; |
| | return 0; |
| | } |
| |
|
| | int |
| | der_copy_utf8string (const heim_utf8_string *from, heim_utf8_string *to) |
| | { |
| | return der_copy_general_string(from, to); |
| | } |
| |
|
| | int |
| | der_copy_printable_string (const heim_printable_string *from, |
| | heim_printable_string *to) |
| | { |
| | return der_copy_general_string(from, to); |
| | } |
| |
|
| | int |
| | der_copy_ia5_string (const heim_printable_string *from, |
| | heim_printable_string *to) |
| | { |
| | return der_copy_general_string(from, to); |
| | } |
| |
|
| | int |
| | der_copy_bmp_string (const heim_bmp_string *from, heim_bmp_string *to) |
| | { |
| | to->length = from->length; |
| | to->data = malloc(to->length * sizeof(to->data[0])); |
| | if(to->length != 0 && to->data == NULL) |
| | return ENOMEM; |
| | memcpy(to->data, from->data, to->length * sizeof(to->data[0])); |
| | return 0; |
| | } |
| |
|
| | int |
| | der_copy_universal_string (const heim_universal_string *from, |
| | heim_universal_string *to) |
| | { |
| | to->length = from->length; |
| | to->data = malloc(to->length * sizeof(to->data[0])); |
| | if(to->length != 0 && to->data == NULL) |
| | return ENOMEM; |
| | memcpy(to->data, from->data, to->length * sizeof(to->data[0])); |
| | return 0; |
| | } |
| |
|
| | int |
| | der_copy_visible_string (const heim_visible_string *from, |
| | heim_visible_string *to) |
| | { |
| | return der_copy_general_string(from, to); |
| | } |
| |
|
| | int |
| | der_copy_octet_string (const heim_octet_string *from, heim_octet_string *to) |
| | { |
| | to->length = from->length; |
| | to->data = malloc(to->length); |
| | if(to->length != 0 && to->data == NULL) |
| | return ENOMEM; |
| | memcpy(to->data, from->data, to->length); |
| | return 0; |
| | } |
| |
|
| | int |
| | der_copy_heim_integer (const heim_integer *from, heim_integer *to) |
| | { |
| | to->length = from->length; |
| | to->data = malloc(to->length); |
| | if(to->length != 0 && to->data == NULL) |
| | return ENOMEM; |
| | memcpy(to->data, from->data, to->length); |
| | to->negative = from->negative; |
| | return 0; |
| | } |
| |
|
| | int |
| | der_copy_oid (const heim_oid *from, heim_oid *to) |
| | { |
| | to->length = from->length; |
| | to->components = malloc(to->length * sizeof(*to->components)); |
| | if (to->length != 0 && to->components == NULL) |
| | return ENOMEM; |
| | memcpy(to->components, from->components, |
| | to->length * sizeof(*to->components)); |
| | return 0; |
| | } |
| |
|
| | int |
| | der_copy_bit_string (const heim_bit_string *from, heim_bit_string *to) |
| | { |
| | size_t len; |
| |
|
| | len = (from->length + 7) / 8; |
| | to->length = from->length; |
| | to->data = malloc(len); |
| | if(len != 0 && to->data == NULL) |
| | return ENOMEM; |
| | memcpy(to->data, from->data, len); |
| | return 0; |
| | } |
| | ",ghmajx/asuswrt-merlin,release/src/router/samba-3.5.8/source4/heimdal/lib/asn1/der_copy.c,C,gpl-2.0,4326 |
| |
|