Ejemplo n.º 1
0
 private BufferedWriter newBufferedWriter(
     String file, ExistingFileBehavior existingFileBehavior, Arg1<Object> fileExistsErrorMsg)
     throws IOException {
   switch (existingFileBehavior) {
     case APPEND:
       return new BufferedWriter(new FileWriter(file, true));
     case OVERWRITE:
       return new BufferedWriter(new FileWriter(file, false));
     case FAIL:
       File f = new File(file);
       if (f.exists()) {
         throw new IOException(fileExistsErrorMsg.get(file).toString());
       }
       return new BufferedWriter(new FileWriter(file));
     default:
       return null;
   }
 }
Ejemplo n.º 2
0
 private Integer getIntegerUserAttribute(
     Entry userEntry,
     String attributeTypeName,
     Arg1<Object> nonUniqueAttributeMessage,
     Arg2<Object, Object> cannotProcessAttributeMessage) {
   AttributeType attrType = DirectoryServer.getAttributeTypeOrDefault(attributeTypeName);
   List<Attribute> attrList = userEntry.getAttribute(attrType);
   if (attrList != null && attrList.size() == 1) {
     Attribute a = attrList.get(0);
     if (a.size() == 1) {
       ByteString v = a.iterator().next();
       try {
         return Integer.valueOf(v.toString());
       } catch (Exception e) {
         logger.traceException(e);
         logger.error(cannotProcessAttributeMessage.get(v, userEntry.getName()));
       }
     } else if (a.size() > 1) {
       logger.error(nonUniqueAttributeMessage.get(userEntry.getName()));
     }
   }
   return null;
 }