Java 类java.util.InvalidPropertiesFormatException 实例源码

项目:incubator-netbeans    文件:ProfilingPointFactory.java   
ProfilingPoint[] loadProfilingPoints(Lookup.Provider project)
                              throws IOException, InvalidPropertiesFormatException {
    Properties properties = new Properties();
    ProfilerStorage.loadProjectProperties(properties, project, getProfilingPointsStorage());

    int index = 0;
    List<ProfilingPoint> profilingPoints = new ArrayList();
    while (properties.getProperty(index + "_" + ProfilingPoint.PROPERTY_NAME) != null) { // NOI18N
        ProfilingPoint profilingPoint = loadProfilingPoint(project, properties, index);

        if (profilingPoint != null) {
            profilingPoints.add(profilingPoint);
        } else {
            ErrorManager.getDefault().log(ErrorManager.ERROR, "Invalid " + getType() + // NOI18N
                                         " Profiling Point format at index " + index +  // NOI18N
                                         " in project " + ProjectUtilities.getDisplayName(project)); // NOI18N
        }

        index++;
    }

    return profilingPoints.toArray(new ProfilingPoint[0]);
}
项目:cassette-nibbler    文件:EncodingScheme.java   
private void readValuesFromConfiguration(String config) throws InvalidPropertiesFormatException {
    if (config == null) {
        throw new InvalidPropertiesFormatException("Invalid properties format: null");
    }

    String[] values = config.split(separator);
    if (values.length < 4)
        throw new InvalidPropertiesFormatException(config);

    zeroBit = charArrayFrom(values[0]);
    oneBit = charArrayFrom(values[1]);

    try {
        paddingBetweenBytes = Integer.parseInt(values[2]);
        mostSignificantBitFirst = values[3].startsWith(mostSignificantBitFirstIndicator);
        pulseExtractiorParameters = new PulseExtractiorParameters();
        if (values.length > 4)
            getPulseParametersFromTaps(values, 4);
    } catch (Throwable t) {
        throw new InvalidPropertiesFormatException("Cannot parse configuration string (" + t.toString() + "): " + config);
    }
}
项目:cassette-nibbler    文件:EncodingScheme.java   
private void getPulseParametersFromTaps(String [] values, int startingIndex) throws InvalidPropertiesFormatException {
    if (values.length < startingIndex + 3)
        throw new InvalidPropertiesFormatException("Invalid properties. Cannot get pulse length values");

    try {
        for (int i = 0; i < 3; i++) {
            int numberOfTaps = Integer.parseInt(values[startingIndex + i]);
            switch (i) {
                case 0:
                    pulseExtractiorParameters.shortPulseLength = pulseExtractiorParameters.secondsForTaps(numberOfTaps);
                    break;
                case 1:
                    pulseExtractiorParameters.mediumPulseLength = pulseExtractiorParameters.secondsForTaps(numberOfTaps);
                    break;
                case 2:
                    pulseExtractiorParameters.longPulseLength = pulseExtractiorParameters.secondsForTaps(numberOfTaps);
                    break;
            }
        }
    } catch (Throwable t) {
        throw new InvalidPropertiesFormatException("Invalid properties.");
    }
}
项目:OpenJSharp    文件:PropertiesDefaultHandler.java   
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException
{
    this.properties = props;

    try {
        SAXParser parser = new SAXParserImpl();
        parser.parse(in, this);
    } catch (SAXException saxe) {
        throw new InvalidPropertiesFormatException(saxe);
    }

    /**
     * String xmlVersion = propertiesElement.getAttribute("version"); if
     * (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
     * InvalidPropertiesFormatException( "Exported Properties file format
     * version " + xmlVersion + " is not supported. This java installation
     * can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
     * " may need to install a newer version of JDK.");
     */
}
项目:jdk8u-jdk    文件:PropertiesDefaultHandler.java   
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException
{
    this.properties = props;

    try {
        SAXParser parser = new SAXParserImpl();
        parser.parse(in, this);
    } catch (SAXException saxe) {
        throw new InvalidPropertiesFormatException(saxe);
    }

    /**
     * String xmlVersion = propertiesElement.getAttribute("version"); if
     * (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
     * InvalidPropertiesFormatException( "Exported Properties file format
     * version " + xmlVersion + " is not supported. This java installation
     * can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
     * " may need to install a newer version of JDK.");
     */
}
项目:openjdk-jdk10    文件:PropertiesDefaultHandler.java   
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException
{
    this.properties = props;

    try {
        SAXParser parser = new SAXParserImpl();
        parser.parse(in, this);
    } catch (SAXException saxe) {
        throw new InvalidPropertiesFormatException(saxe);
    }

    /**
     * String xmlVersion = propertiesElement.getAttribute("version"); if
     * (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
     * InvalidPropertiesFormatException( "Exported Properties file format
     * version " + xmlVersion + " is not supported. This java installation
     * can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
     * " may need to install a newer version of JDK.");
     */
}
项目:openjdk-jdk10    文件:LoadAndStoreXML.java   
/**
 * Test loadFromXML with malformed documents
 */
static void testLoadWithMalformedDoc(Path dir) throws IOException {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.xml")) {
        for (Path file: stream) {
            System.out.println("testLoadWithMalformedDoc, file=" + file.getFileName());
            try (InputStream in = Files.newInputStream(file)) {
                Properties props = new Properties();
                try {
                    props.loadFromXML(in);
                    throw new RuntimeException("InvalidPropertiesFormatException not thrown");
                } catch (InvalidPropertiesFormatException x) {
                    System.out.println(x);
                }
            }
        }
    }
}
项目:hotelApp    文件:DatabaseConnector.java   
/**
 * Attempts to load properties file with database configuration. Must
 * include username, password, database, and hostname.
 *
 * @param configPath path to database properties file
 * @return database properties
 * @throws IOException if unable to properly parse properties file
 * @throws FileNotFoundException if properties file not found
 */
private Properties loadConfig(String configPath) throws FileNotFoundException, IOException {

    // Specify which keys must be in properties file
    Set<String> required = new HashSet<>();
    required.add("username");
    required.add("password");
    required.add("database");
    required.add("hostname");

    // Load properties file
    Properties config = new Properties();
    config.load(new FileReader(configPath));

    // Check that required keys are present
    if (!config.keySet().containsAll(required)) {
        String error = "Must provide the following in properties file: ";
        throw new InvalidPropertiesFormatException(error + required);
    }

    return config;
}
项目:openjdk9    文件:PropertiesDefaultHandler.java   
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException
{
    this.properties = props;

    try {
        SAXParser parser = new SAXParserImpl();
        parser.parse(in, this);
    } catch (SAXException saxe) {
        throw new InvalidPropertiesFormatException(saxe);
    }

    /**
     * String xmlVersion = propertiesElement.getAttribute("version"); if
     * (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
     * InvalidPropertiesFormatException( "Exported Properties file format
     * version " + xmlVersion + " is not supported. This java installation
     * can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
     * " may need to install a newer version of JDK.");
     */
}
项目:openjdk9    文件:LoadAndStoreXML.java   
/**
 * Test loadFromXML with malformed documents
 */
static void testLoadWithMalformedDoc(Path dir) throws IOException {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.xml")) {
        for (Path file: stream) {
            System.out.println("testLoadWithMalformedDoc, file=" + file.getFileName());
            try (InputStream in = Files.newInputStream(file)) {
                Properties props = new Properties();
                try {
                    props.loadFromXML(in);
                    throw new RuntimeException("InvalidPropertiesFormatException not thrown");
                } catch (InvalidPropertiesFormatException x) {
                    System.out.println(x);
                }
            }
        }
    }
}
项目:services-in-one    文件:ExceptionAutoConfigurationTest.java   
@Test
public void testExceptionHttpStatusMapWithOneGoodNumberAndOneGoodName() throws Exception {
    final Class<IllegalArgumentException> clazz1 = IllegalArgumentException.class;
    final HttpStatus status1 = HttpStatus.OK;
    final Class<InvalidPropertiesFormatException> clazz2 = InvalidPropertiesFormatException.class;
    final HttpStatus status2 = HttpStatus.ACCEPTED;
    final Map<String, String> m = new HashMap<String, String>() {{
        put(clazz1.getName(), status1.toString());
        put(clazz2.getName(), status2.name());
    }};
    doReturn(m).when(properties).getMappings();

    final ExceptionHttpStatusMap map = configuration.exceptionHttpStatusMap();

    assertThat(map.size(), is(equalTo(8)));
    assertThat(map.get(clazz1), is(equalTo(status1)));
    assertThat(map.get(clazz2), is(equalTo(status2)));
}
项目:services-in-one    文件:ExceptionAutoConfigurationTest.java   
@Test
public void testExceptionHttpStatusMapWithOneBadNumberAndOneGoodName() throws Exception {
    final Class<IllegalArgumentException> clazz1 = IllegalArgumentException.class;
    final String status1 = "0";
    final Class<InvalidPropertiesFormatException> clazz2 = InvalidPropertiesFormatException.class;
    final HttpStatus status2 = HttpStatus.ACCEPTED;
    final Map<String, String> m = new HashMap<String, String>() {{
        put(clazz1.getName(), status1);
        put(clazz2.getName(), status2.name());
    }};
    doReturn(m).when(properties).getMappings();

    final ExceptionHttpStatusMap map = configuration.exceptionHttpStatusMap();

    assertThat(map.size(), is(equalTo(7)));
    assertThat(map.get(clazz1), is(equalTo(DEFAULT_HTTP_STATUS)));
    assertThat(map.get(clazz2), is(equalTo(status2)));
}
项目:jdk8u_jdk    文件:PropertiesDefaultHandler.java   
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException
{
    this.properties = props;

    try {
        SAXParser parser = new SAXParserImpl();
        parser.parse(in, this);
    } catch (SAXException saxe) {
        throw new InvalidPropertiesFormatException(saxe);
    }

    /**
     * String xmlVersion = propertiesElement.getAttribute("version"); if
     * (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
     * InvalidPropertiesFormatException( "Exported Properties file format
     * version " + xmlVersion + " is not supported. This java installation
     * can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
     * " may need to install a newer version of JDK.");
     */
}
项目:lookaside_java-1.8.0-openjdk    文件:PropertiesDefaultHandler.java   
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException
{
    this.properties = props;

    try {
        SAXParser parser = new SAXParserImpl();
        parser.parse(in, this);
    } catch (SAXException saxe) {
        throw new InvalidPropertiesFormatException(saxe);
    }

    /**
     * String xmlVersion = propertiesElement.getAttribute("version"); if
     * (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
     * InvalidPropertiesFormatException( "Exported Properties file format
     * version " + xmlVersion + " is not supported. This java installation
     * can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
     * " may need to install a newer version of JDK.");
     */
}
项目:TranskribusSwtGui    文件:TrpVirtualKeyboardsTabWidget.java   
private static List<UnicodeList> loadVirtualKeyboardsXml(XMLPropertiesConfiguration conf)
        throws InvalidPropertiesFormatException, FileNotFoundException, IOException {

    List<UnicodeList> unicodeLists = new ArrayList<>();     
    Iterator<String> it=conf.getKeys();
    while (it.hasNext()) {
        String key = it.next();
        String value = conf.getString(key);
        logger.info("value = '"+value+"'");

        UnicodeList ul = new UnicodeList(key, value);
        unicodeLists.add(ul);
    }
    Collections.sort(unicodeLists);

    return unicodeLists;
}
项目:teams-game    文件:XmlMetaParser.java   
private String valueOrDefault(Element parentNode, String key, FieldProvider def) throws InvalidPropertiesFormatException {
    // Handle parent undefined:
    if (parentNode == null)
        return def.getPropertyValue(key);

    NodeList nodes = parentNode.getElementsByTagName(key);

    // Handle multiple nodes
    if (nodes.getLength() > 1)
        throw new InvalidPropertiesFormatException(String.format(
                "\"<%s>\" should contain only one \"<%s>\" element.", parentNode.getNodeName(), key));
    // No nodes
    if (nodes.getLength() == 0)
        return def.getPropertyValue(key);

    return nodes.item(0).getTextContent();
}
项目:chilo-producer    文件:Config.java   
private void read(Path path) throws InvalidPropertiesFormatException, IOException, Epub3MakerException {
    InputStream stream = new FileInputStream(path.toFile());
    prop.loadFromXML(stream);
    stream.close();

    if (log.isDebugEnabled()) {
        log.debug("show settings in " + path);
        prop.list(System.out);
    }

    if (prop.getProperty(SeriesBaseDirKey) == null) {
        throw new Epub3MakerException("!!! SeriesBaseDir is not set !!!");
    }
    if (prop.getProperty(OutputBaseDirKey) == null) {
        throw new Epub3MakerException("!!! OutputBaseDir is not set !!!");
    }
    if (prop.getProperty(TemplateBaseDirKey) == null) {
        throw new Epub3MakerException("!!! TemplateBaseDir is not set !!!");
    }
}
项目:chilo-producer    文件:Config.java   
public Config(String filename, String homeDir) throws InvalidPropertiesFormatException, IOException, Epub3MakerException {
    if(homeDir != null){
        homePath = Paths.get(homeDir);
    }

    Path path = null;
    if(filename != null){
path = Paths.get(filename);
    } else if(homePath != null){
        path = homePath.resolve(defaultFilename);
    } else {
        path = Paths.get(defaultFilename);
    }

    read(path);

    if(homePath != null){
        String str = prop.getProperty(TemplateBaseDirKey);
        str = homePath.resolve(str).toString();
        prop.setProperty(TemplateBaseDirKey, str);

        prop.setProperty(ExtensionBaseDirKey, homePath.toString());
    }
 }
项目:infobip-open-jdk-8    文件:PropertiesDefaultHandler.java   
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException
{
    this.properties = props;

    try {
        SAXParser parser = new SAXParserImpl();
        parser.parse(in, this);
    } catch (SAXException saxe) {
        throw new InvalidPropertiesFormatException(saxe);
    }

    /**
     * String xmlVersion = propertiesElement.getAttribute("version"); if
     * (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
     * InvalidPropertiesFormatException( "Exported Properties file format
     * version " + xmlVersion + " is not supported. This java installation
     * can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
     * " may need to install a newer version of JDK.");
     */
}
项目:jdk8u-dev-jdk    文件:PropertiesDefaultHandler.java   
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException
{
    this.properties = props;

    try {
        SAXParser parser = new SAXParserImpl();
        parser.parse(in, this);
    } catch (SAXException saxe) {
        throw new InvalidPropertiesFormatException(saxe);
    }

    /**
     * String xmlVersion = propertiesElement.getAttribute("version"); if
     * (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
     * InvalidPropertiesFormatException( "Exported Properties file format
     * version " + xmlVersion + " is not supported. This java installation
     * can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
     * " may need to install a newer version of JDK.");
     */
}
项目:In-the-Box-Fork    文件:InvalidPropertiesFormatExceptionTest.java   
/**
 * @tests java.util.InvalidPropertiesFormatException#SerializationTest()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "Verifies serialization/deserialization compatibility.",
    method = "!SerializationSelf",
    args = {}
)
public void test_Serialization() throws Exception {
    InvalidPropertiesFormatException ipfe = new InvalidPropertiesFormatException(
            "Hey, this is InvalidPropertiesFormatException");
    try {
        SerializationTest.verifySelf(ipfe);
    } catch (NotSerializableException e) {
        // expected
    }
}
项目:RaspberryPiBeaconParser    文件:ScannerHandler.java   
/**
    * Message format is length, byte[length] = destinationID, length, byte[length] = body
    * @throws IOException
    */
   private void doRun() throws IOException {
      while(running) {
         int length = clientStream.readInt();
//         System.out.printf("Reading destination of size: %d\n", length);
         byte[] destinationID = new byte[length];
         clientStream.readFully(destinationID);
//         System.out.printf("destinationID=%s\n", new String(destinationID));
         length = clientStream.readInt();
//         System.out.printf("Reading msg of size: %d\n", length);
         byte[] msg = new byte[length];
         clientStream.readFully(msg);
         try {
            store.store(destinationID, msg);
         } catch (InvalidPropertiesFormatException e) {
            // Exception thrown to log the client connection generating the error
            System.err.printf("Invalid properties msg sent by: %s\n", this);
         }
      }
   }
项目:OLD-OpenJDK8    文件:PropertiesDefaultHandler.java   
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException
{
    this.properties = props;

    try {
        SAXParser parser = new SAXParserImpl();
        parser.parse(in, this);
    } catch (SAXException saxe) {
        throw new InvalidPropertiesFormatException(saxe);
    }

    /**
     * String xmlVersion = propertiesElement.getAttribute("version"); if
     * (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
     * InvalidPropertiesFormatException( "Exported Properties file format
     * version " + xmlVersion + " is not supported. This java installation
     * can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
     * " may need to install a newer version of JDK.");
     */
}
项目:opensearchserver    文件:AutoCompletionComposer.java   
@Command
@NotifyChange("*")
public void onSave() throws SearchLibException,
        InvalidPropertiesFormatException, IOException {
    Client client = getClient();
    if (client == null)
        return;
    AutoCompletionManager manager = client.getAutoCompletionManager();
    AutoCompletionItem autoCompItem = selectedItem != null ? selectedItem
            : new AutoCompletionItem(client, name);
    autoCompItem.setFields(fields);
    autoCompItem.setRows(rows);
    autoCompItem.setSearchRequest(searchRequest);
    if (selectedItem == null)
        manager.add(autoCompItem);
    else
        autoCompItem.save();
    onCancel();
}
项目:opensearchserver    文件:AutoCompletionManager.java   
public AutoCompletionManager(Config config) throws SearchLibException,
        IOException {
    this.config = config;
    autoCompletionDirectory = new File(config.getDirectory(),
            autoCompletionSubDirectory);
    if (!autoCompletionDirectory.exists())
        autoCompletionDirectory.mkdir();
    autoCompItems = new TreeSet<AutoCompletionItem>();
    File[] autoCompFiles = autoCompletionDirectory
            .listFiles((FileFilter) new SuffixFileFilter(".xml"));
    if (autoCompFiles == null)
        return;
    for (File autoCompFile : autoCompFiles) {
        try {
            add(new AutoCompletionItem(config, autoCompFile));
        } catch (InvalidPropertiesFormatException e) {
            Logging.warn("Invalid autocompletion file: "
                    + autoCompFile.getAbsolutePath());
        }
    }
}
项目:jMyCTMC    文件:MyROPropertiesSingleton.java   
private MyROPropertiesSingleton() throws InvalidPropertiesFormatException, IOException {
    Properties def = new Properties();
    FileInputStream in = new FileInputStream("defaultConfiguration.xml");

    def.loadFromXML(in);
    in.close();
    this.prop = new Properties(def);
    in = new FileInputStream(
            this.prop.getProperty(
                    "appConfigurationFileName",
                    "AppConfiguration.xml"
                    )
            );
    this.prop.loadFromXML(in);
    in.close();
}
项目:cassette-nibbler    文件:C64TurboLoadExtractionPlatform.java   
private void useSchemeSpecifiedInPlatformSettings() {
    try {
        EncodingScheme schemeToUse = new EncodingScheme(platformSettings);
        schemeList = new LinkedList<>();
        schemeList.add(schemeToUse);
    } catch (InvalidPropertiesFormatException e) {
        System.err.println("Invalid encoding scheme specified: " + e.toString());
    }
}
项目:cassette-nibbler    文件:AutomaticExtractionPlatform.java   
private void useSchemeSpecifiedInPlatformSettings() {
    try {
        EncodingScheme schemeToUse = new EncodingScheme(platformSettings);
        schemeList = new LinkedList<>();
        schemeList.add(schemeToUse);
    } catch (InvalidPropertiesFormatException e) {
        System.err.println("Invalid encoding scheme specified: " + e.toString());
    }
}
项目:JavaGraph    文件:Properties.java   
@Override
public synchronized void loadFromXML(InputStream in)
    throws IOException, InvalidPropertiesFormatException {
    testFixed(false);
    clear();
    super.loadFromXML(in);
}
项目:OpenJSharp    文件:BasicXmlPropertiesProvider.java   
@Override
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException
{
    PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
    handler.load(props, in);
}
项目:jdk8u-jdk    文件:BasicXmlPropertiesProvider.java   
@Override
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException
{
    PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
    handler.load(props, in);
}
项目:scipio-erp    文件:UtilProperties.java   
public ExtendedProperties(URL url, Locale locale) throws IOException, InvalidPropertiesFormatException {
    InputStream in = new BufferedInputStream(url.openStream());
    if (url.getFile().endsWith(".xml")) {
        xmlToProperties(in, locale, this);
    } else {
        load(in);
    }
    in.close();
}
项目:venus    文件:ObjectMapLoader.java   
/**
 * Version number for the format of exported properties files.
 */

public static void load(Map<String, Object> props, InputStream in) throws IOException, InvalidPropertiesFormatException {
    Document doc = null;
    try {
        doc = getLoadingDoc(in);
    } catch (SAXException saxe) {
        throw new InvalidPropertiesFormatException(saxe);
    }
    Element propertiesElement = (Element) doc.getChildNodes().item(1);
    importMap(props, propertiesElement);
}
项目:jdk8u_jdk    文件:BasicXmlPropertiesProvider.java   
@Override
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException
{
    PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
    handler.load(props, in);
}
项目:lookaside_java-1.8.0-openjdk    文件:BasicXmlPropertiesProvider.java   
@Override
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException
{
    PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
    handler.load(props, in);
}
项目:BeaconFinder    文件:BluetoothScannerService.java   
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] data) {
    /**
     * Depending on beacon advert frequency, we get multiple callbacks from many devices
     * Check that this isn't a device we have already seen, and add it to the list.
     */
    if (!mScanHistory.containsKey(device.getAddress())) {
        mScanHistory.put(device.getAddress(), new LinkedBlockingDeque<Integer>());

        if (device.getType() == BluetoothDevice.DEVICE_TYPE_LE
                || device.getAddress().startsWith(CAMBRIDGE_TAG)) {
            try {

                ScanItem item = mParser.handleFoundDevice(device, rssi, data);
                mScanResults.add(item);
                mScanHistory.get(device.getAddress()).add(rssi);
            } catch (InvalidPropertiesFormatException e) {
                Log.d(TAG, "Skipping BLE device, not an iBeacon" + device.toString());
            }
        }
    }
    // Else, add the device to the history, pop first if history gets to big
    // This will let us do some normalization of the values on each scan cycle
    else {
           if (mScanHistory.get(device.getAddress()).size() > BUFFER_SIZE)
                mScanHistory.get(device.getAddress()).removeFirst();
            mScanHistory.get(device.getAddress()).add(rssi);
    }
}
项目:teams-game    文件:XmlMetaParser.java   
private QuestCollection generateCollection(Element document) throws InvalidPropertiesFormatException {
    QuestCollection qc = new QuestCollection();
    FieldProvider defaults = defaultsFactory.getCollectionDefaults();

    // Check if root node is <document>...
    if (!document.getNodeName().equalsIgnoreCase(KEY_XML_ROOT_NODE)) {
        throw new InvalidPropertiesFormatException(
                "Document should start with \"<" + KEY_XML_ROOT_NODE + ">\" root node.");
    }

    // ...it should contain only one <meta> tag
    Element meta = getSingleContainerElement(document, KEY_XML_QUESTCOLLECTION_META);

    qc.setId(collectionId);
    qc.setTitle(valueOrDefault(meta, KEY_QUESTCOLLECTION_TITLE, defaults));
    qc.setSubtitle(valueOrDefault(meta, KEY_QUESTCOLLECTION_SUBTITLE, defaults));
    qc.setDescription(valueOrDefault(meta, KEY_QUESTCOLLECTION_DESCRIPTION, defaults));

    String iconPathStr = valueOrDefault(meta, KEY_QUESTCOLLECTION_PATH_ICON, defaults);
    qc.setIconUrl(LevelAssetsURLStreamHandler.createURL(collectionId, iconPathStr));

    // ...and only one <content> tag with <quest> children
    Element content = getSingleContainerElement(document, KEY_XML_QUESTCOLLECTION_ELEMENTS);
    if (content == null) {
        // No quests content
        return qc;
    }

    NodeList quests = content.getElementsByTagName(KEY_XML_QUEST_NODE);
    int questIndex = 0;
    for (int i = 0; i < quests.getLength(); i++) {
        if (quests.item(i).getNodeType() == Node.ELEMENT_NODE) {
            qc.addQuest(generateQuest(questIndex, (Element) quests.item(i)));
            ++questIndex;
        }
    }

    return qc;
}
项目:teams-game    文件:XmlMetaParser.java   
private Element getSingleContainerElement(Element parentNode, String key) throws InvalidPropertiesFormatException {
    NodeList elements = parentNode.getElementsByTagName(key);

    if (elements.getLength() > 1)
        throw new InvalidPropertiesFormatException("Collection should have only one \"<" + key + ">\" node.");

    // Node type check should be short-circuited if empty check fails, so it should not throw.
    if (elements.getLength() == 0 || elements.item(0).getNodeType() != Node.ELEMENT_NODE) {
        // No node or wrong format
        return null;
    }

    return (Element) elements.item(0);
}
项目:infobip-open-jdk-8    文件:BasicXmlPropertiesProvider.java   
@Override
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException
{
    PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
    handler.load(props, in);
}
项目:jdk8u-dev-jdk    文件:BasicXmlPropertiesProvider.java   
@Override
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException
{
    PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
    handler.load(props, in);
}