Clean code.

This commit is contained in:
Christian P. MOMON 2013-06-20 01:08:32 +02:00
parent 447d1f273b
commit 047e945ab0
36 changed files with 3391 additions and 3393 deletions

View file

@ -1,4 +1,3 @@
#Wed Mar 31 13:06:06 CEST 2010
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
@ -10,3 +9,283 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
org.eclipse.jdt.core.formatter.blank_lines_before_field=0
org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
org.eclipse.jdt.core.formatter.blank_lines_before_method=1
org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
org.eclipse.jdt.core.formatter.blank_lines_before_package=0
org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=next_line
org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=next_line
org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_block=next_line
org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=next_line
org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=next_line
org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=next_line
org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=next_line
org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=next_line
org.eclipse.jdt.core.formatter.brace_position_for_switch=next_line
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=next_line
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
org.eclipse.jdt.core.formatter.comment.format_block_comments=false
org.eclipse.jdt.core.formatter.comment.format_header=false
org.eclipse.jdt.core.formatter.comment.format_html=true
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
org.eclipse.jdt.core.formatter.comment.format_line_comments=true
org.eclipse.jdt.core.formatter.comment.format_source_code=true
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false
org.eclipse.jdt.core.formatter.compact_else_if=true
org.eclipse.jdt.core.formatter.continuation_indentation=2
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_empty_lines=false
org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
org.eclipse.jdt.core.formatter.indentation.size=4
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert
org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=insert
org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert
org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.join_lines_in_comments=true
org.eclipse.jdt.core.formatter.join_wrapped_lines=true
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
org.eclipse.jdt.core.formatter.lineSplit=200
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=tab
org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true

View file

@ -0,0 +1,3 @@
eclipse.preferences.version=1
formatter_profile=_Devinsy
formatter_settings_version=12

View file

@ -5,7 +5,6 @@
*/ */
package fr.devinsy.util; package fr.devinsy.util;
/** /**
* This class defines a content file. * This class defines a content file.
* *
@ -41,21 +40,7 @@ public class DataFile
/** /**
* *
*/ */
public DataFile (String name, long size, byte[] data) public DataFile(final int contentId, final String name, final long size, final byte[] data)
{
this.id = NOID;
this.contentId = NOID;
this.name = name;
this.size = size;
this.data = data;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public DataFile (int contentId, String name, long size, byte[] data)
{ {
this.id = NOID; this.id = NOID;
this.contentId = contentId; this.contentId = contentId;
@ -69,23 +54,15 @@ public class DataFile
/** /**
* *
*/ */
public int id () public DataFile(final String name, final long size, final byte[] data)
{ {
int result; this.id = NOID;
this.contentId = NOID;
result = this.id; this.name = name;
this.size = size;
// this.data = data;
return (result); this.creationDate = null;
} this.creationUser = null;
/**
*
*/
public void setId (int id)
{
this.id = id;
} }
/** /**
@ -101,91 +78,6 @@ public class DataFile
return (result); return (result);
} }
/**
*
*/
public void setContentId (int contentId)
{
this.contentId = contentId;
}
/**
*
*/
public String name ()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public void setName (String name)
{
if (name == null)
{
this.name = "";
}
else
{
this.name = name;
}
}
/**
*
*/
public long size ()
{
long result;
result = this.size;
//
return (result);
}
/**
*
*/
public void setSize (long size)
{
if (size >= 0)
{
this.size = size;
}
else
{
this.size = 0;
}
}
/**
*
*/
public byte[] data ()
{
byte[] result;
result = this.data;
//
return (result);
}
/**
*
*/
public void setData (byte[] data)
{
this.data = data;
}
/** /**
* *
*/ */
@ -199,21 +91,6 @@ public class DataFile
return (result); return (result);
} }
/**
*
*/
public void setCreationDate (String creationDate)
{
if (creationDate == null)
{
this.creationDate = "";
}
else
{
this.creationDate = creationDate;
}
}
/** /**
* *
*/ */
@ -230,7 +107,69 @@ public class DataFile
/** /**
* *
*/ */
public void setCreationUser (String creationUser) public byte[] data()
{
byte[] result;
result = this.data;
//
return (result);
}
/**
*
*/
public int id()
{
int result;
result = this.id;
//
return (result);
}
/**
*
*/
public String name()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public void setContentId(final int contentId)
{
this.contentId = contentId;
}
/**
*
*/
public void setCreationDate(final String creationDate)
{
if (creationDate == null)
{
this.creationDate = "";
}
else
{
this.creationDate = creationDate;
}
}
/**
*
*/
public void setCreationUser(final String creationUser)
{ {
if (creationUser == null) if (creationUser == null)
{ {
@ -241,4 +180,63 @@ public class DataFile
this.creationUser = creationUser; this.creationUser = creationUser;
} }
} }
/**
*
*/
public void setData(final byte[] data)
{
this.data = data;
}
/**
*
*/
public void setId(final int id)
{
this.id = id;
}
/**
*
*/
public void setName(final String name)
{
if (name == null)
{
this.name = "";
}
else
{
this.name = name;
}
}
/**
*
*/
public void setSize(final long size)
{
if (size >= 0)
{
this.size = size;
}
else
{
this.size = 0;
}
}
/**
*
*/
public long size()
{
long result;
result = this.size;
//
return (result);
}
} }

View file

@ -11,11 +11,10 @@ import java.util.ArrayList;
* This class is a collection of DataFile objects whit some specific methods. * This class is a collection of DataFile objects whit some specific methods.
* *
*/ */
public class DataFiles extends ArrayList public class DataFiles extends ArrayList<DataFile>
{ {
private static final long serialVersionUID = -4584622422555785456L; private static final long serialVersionUID = -4584622422555785456L;
/** /**
* *
* *
@ -25,67 +24,29 @@ public class DataFiles extends ArrayList
super(); super();
} }
/** /**
* *
* @param source * @param source
*/ */
public DataFiles (DataFiles source) public DataFiles(final DataFiles source)
{ {
super(source); super(source);
} }
/** /**
* *
*/ */
public DataFile getByIndex (int index) public DataFiles getByContentId(final int id)
{ {
DataFile result; DataFiles result = new DataFiles();
result = (DataFile) super.get (index); for (int nDataFile = 0; nDataFile < this.size(); nDataFile++)
//
return (result);
}
/**
*
*/
public DataFile getByName (String name)
{
DataFile result = null;
if ((name == null) || (name.equals ("")))
{
result = null;
}
else
{
boolean ended = false;
int nDataFile = 0;
while (!ended)
{
if (nDataFile >= this.size())
{
ended = true;
result = null;
}
else
{ {
DataFile contentFile = this.getByIndex(nDataFile); DataFile contentFile = this.getByIndex(nDataFile);
if (name.equals(contentFile.name())) if (contentFile.contentId() == id)
{ {
ended = true; result.add(contentFile);
result = contentFile;
}
else
{
nDataFile += 1;
}
}
} }
} }
@ -96,7 +57,7 @@ public class DataFiles extends ArrayList
/** /**
* *
*/ */
public DataFile getById (int id) public DataFile getById(final int id)
{ {
DataFile result = null; DataFile result = null;
@ -129,21 +90,55 @@ public class DataFiles extends ArrayList
return (result); return (result);
} }
/**
*
*/
public DataFile getByIndex(final int index)
{
DataFile result;
result = super.get(index);
//
return (result);
}
/** /**
* *
*/ */
public DataFiles getByContentId (int id) public DataFile getByName(final String name)
{ {
DataFiles result = new DataFiles(); DataFile result = null;
for (int nDataFile = 0; nDataFile < this.size(); nDataFile++) if ((name == null) || (name.equals("")))
{ {
DataFile contentFile = this.getByIndex(nDataFile); result = null;
}
else
{
boolean ended = false;
int dataFileIndex = 0;
while (!ended)
{
if (dataFileIndex >= this.size())
{
ended = true;
result = null;
}
else
{
DataFile contentFile = this.getByIndex(dataFileIndex);
if (contentFile.contentId() == id) if (name.equals(contentFile.name()))
{ {
result.add(contentFile); ended = true;
result = contentFile;
}
else
{
dataFileIndex += 1;
}
}
} }
} }
@ -151,10 +146,10 @@ public class DataFiles extends ArrayList
return (result); return (result);
} }
/** /**
* *
*/ */
@Override
public String toString() public String toString()
{ {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();

View file

@ -10,7 +10,6 @@ import java.util.GregorianCalendar;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* This class groups function to help in Calendar manipulation. * This class groups function to help in Calendar manipulation.
* *
@ -18,7 +17,8 @@ import java.util.regex.Pattern;
*/ */
public class DateHelper public class DateHelper
{ {
//static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (DateHelper.class); // static private org.apache.log4j.Logger logger =
// org.apache.log4j.Logger.getLogger (DateHelper.class);
static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d"; static final String EUROPEAN_DATE_FORMAT = "%02d/%02d/%04d";
static final String SHORT_EUROPEAN_DATE_FORMAT = "%02d/%02d"; static final String SHORT_EUROPEAN_DATE_FORMAT = "%02d/%02d";
@ -31,74 +31,10 @@ public class DateHelper
static final String ISO_DATE_PATTERN = "^(\\d\\d\\d\\d)-([01]\\d)-([0123]\\d)$"; static final String ISO_DATE_PATTERN = "^(\\d\\d\\d\\d)-([01]\\d)-([0123]\\d)$";
static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$"; static final String AMERICAN_DATE_PATTERN = "^([01]{0,1}\\d)/([0123]{0,1}\\d)/(\\d\\d\\d\\d)$";
/** /**
* *
*/ */
static public String europeanFormat (Calendar time) static public String americanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format (EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1, time.get(Calendar.YEAR));
}
//
return (result);
}
/**
*
*/
static public String shortEuropeanFormat (Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format (SHORT_EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1);
}
//
return (result);
}
/**
*
*/
static public String ISOFormat (Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format (ISO_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH));
}
//
return (result);
}
/**
*
*/
static public String americanFormat (Calendar time)
{ {
String result; String result;
@ -115,11 +51,10 @@ public class DateHelper
return (result); return (result);
} }
/** /**
* *
*/ */
static public String rawFormat (Calendar time) static public String europeanFormat(final Calendar time)
{ {
String result; String result;
@ -129,42 +64,37 @@ public class DateHelper
} }
else else
{ {
result = String.format (RAW_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH), time.get(Calendar.DAY_OF_MONTH) + 1); result = String.format(EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1, time.get(Calendar.YEAR));
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
static public boolean isValidDate (String date) static public boolean isAmericanFormat(final String date)
{ {
boolean result; boolean result;
if ((isEuropeanFormat (date)) || if (date == null)
(isRawFormat (date)) ||
(isISOFormat (date)) ||
(isAmericanFormat (date)))
{ {
result = true; result = false;
} }
else else
{ {
result = false; result = date.matches(AMERICAN_DATE_PATTERN);
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
static public boolean isEuropeanFormat (String date) static public boolean isEuropeanFormat(final String date)
{ {
boolean result; boolean result;
@ -184,27 +114,7 @@ public class DateHelper
/** /**
* *
*/ */
static public boolean isRawFormat (String date) static public boolean isISOFormat(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches (RAW_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isISOFormat (String date)
{ {
boolean result; boolean result;
@ -224,7 +134,27 @@ public class DateHelper
/** /**
* *
*/ */
static public boolean isAmericanFormat (String date) static public String ISOFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(ISO_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH));
}
//
return (result);
}
/**
*
*/
static public boolean isRawFormat(final String date)
{ {
boolean result; boolean result;
@ -234,70 +164,37 @@ public class DateHelper
} }
else else
{ {
result = date.matches (AMERICAN_DATE_PATTERN); result = date.matches(RAW_DATE_PATTERN);
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
static public Calendar parseISODate (String date) static public boolean isValidDate(final String date)
{ {
Calendar result; boolean result;
Pattern pattern = Pattern.compile (ISO_DATE_PATTERN); if ((isEuropeanFormat(date)) || (isRawFormat(date)) || (isISOFormat(date)) || (isAmericanFormat(date)))
Matcher matcher = pattern.matcher (date);
if ((matcher.find ()) && (matcher.groupCount () == 3))
{ {
result = new GregorianCalendar (Integer.parseInt (matcher.group (1)), result = true;
Integer.parseInt (matcher.group (2)) - 1,
Integer.parseInt (matcher.group (3)));
} }
else else
{ {
result = null; result = false;
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
static public Calendar parseRawDate (String date) static public Calendar parseAmericanDate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile (RAW_DATE_PATTERN);
Matcher matcher = pattern.matcher (date);
if ((matcher.find ()) && (matcher.groupCount () == 3))
{
result = new GregorianCalendar (Integer.parseInt (matcher.group (1)),
Integer.parseInt (matcher.group (2)) - 1,
Integer.parseInt (matcher.group (3)));
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public Calendar parseAmericanDate (String date)
{ {
Calendar result; Calendar result;
@ -306,9 +203,7 @@ public class DateHelper
if ((matcher.find()) && (matcher.groupCount() == 3)) if ((matcher.find()) && (matcher.groupCount() == 3))
{ {
result = new GregorianCalendar (Integer.parseInt (matcher.group (3)), result = new GregorianCalendar(Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(1)) - 1, Integer.parseInt(matcher.group(2)));
Integer.parseInt (matcher.group (1)) - 1,
Integer.parseInt (matcher.group (2)));
} }
else else
{ {
@ -319,37 +214,10 @@ public class DateHelper
return (result); return (result);
} }
/**
*
*/
static public Calendar parseEuropeanDate (String date)
{
Calendar result;
Pattern pattern = Pattern.compile (EUROPEAN_DATE_PATTERN);
Matcher matcher = pattern.matcher (date);
if ((matcher.find ()) && (matcher.groupCount () == 3))
{
result = new GregorianCalendar (Integer.parseInt (matcher.group (3)),
Integer.parseInt (matcher.group (2)) - 1,
Integer.parseInt (matcher.group (1)));
}
else
{
result = null;
}
//
return (result);
}
/** /**
* Note: European parsing test made before the American parsing one. * Note: European parsing test made before the American parsing one.
*/ */
static public Calendar parseDate (String date) static public Calendar parseDate(final String date)
{ {
Calendar result; Calendar result;
@ -377,4 +245,113 @@ public class DateHelper
// //
return (result); return (result);
} }
/**
*
*/
static public Calendar parseEuropeanDate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile(EUROPEAN_DATE_PATTERN);
Matcher matcher = pattern.matcher(date);
if ((matcher.find()) && (matcher.groupCount() == 3))
{
result = new GregorianCalendar(Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(1)));
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public Calendar parseISODate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile(ISO_DATE_PATTERN);
Matcher matcher = pattern.matcher(date);
if ((matcher.find()) && (matcher.groupCount() == 3))
{
result = new GregorianCalendar(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(3)));
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public Calendar parseRawDate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile(RAW_DATE_PATTERN);
Matcher matcher = pattern.matcher(date);
if ((matcher.find()) && (matcher.groupCount() == 3))
{
result = new GregorianCalendar(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(3)));
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
static public String rawFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(RAW_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH), time.get(Calendar.DAY_OF_MONTH) + 1);
}
//
return (result);
}
/**
*
*/
static public String shortEuropeanFormat(final Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format(SHORT_EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1);
}
//
return (result);
}
} }

View file

@ -11,46 +11,15 @@ import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
/** /**
* This class is a helper to use MessageDigester class. * This class is a helper to use MessageDigester class.
*/ */
public class Digester public class Digester
{ {
/**
*
*/
static public String humanReadableDigest (byte[] digest)
{
String result;
StringBuffer hashString = new StringBuffer ();
for (int letterIndex = 0; letterIndex < digest.length; ++letterIndex)
{
String hex = Integer.toHexString (digest[letterIndex]);
if (hex.length() == 1)
{
hashString.append ('0');
hashString.append (hex.charAt (hex.length () - 1));
}
else
{
hashString.append (hex.substring (hex.length () - 2));
}
}
result = hashString.toString();
//
return (result);
}
/** /**
* "SHA-1", "MD5", "SHA-256", and "SHA-512" * "SHA-1", "MD5", "SHA-256", and "SHA-512"
*/ */
static public String computeHash (String digestMethod, File file) throws Exception static public String computeHash(final String digestMethod, final File file) throws Exception
{ {
String result; String result;
@ -111,4 +80,33 @@ public class Digester
// //
return (result); return (result);
} }
/**
*
*/
static public String humanReadableDigest(final byte[] digest)
{
String result;
StringBuffer hashString = new StringBuffer();
for (int letterIndex = 0; letterIndex < digest.length; ++letterIndex)
{
String hex = Integer.toHexString(digest[letterIndex]);
if (hex.length() == 1)
{
hashString.append('0');
hashString.append(hex.charAt(hex.length() - 1));
}
else
{
hashString.append(hex.substring(hex.length() - 2));
}
}
result = hashString.toString();
//
return (result);
}
} }

View file

@ -4,7 +4,6 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
/** /**
* Never used again. Prefer org.apache.commons.io.FileUtils class. * Never used again. Prefer org.apache.commons.io.FileUtils class.
*/ */
@ -15,7 +14,7 @@ public class FileCopier
/** /**
* *
*/ */
static void copy (File source, File target) throws Exception static void copy(final File source, final File target) throws Exception
{ {
if ((source == null) || (target == null)) if ((source == null) || (target == null))
{ {

View file

@ -1,13 +1,10 @@
package fr.devinsy.util; package fr.devinsy.util;
import java.io.File; import java.io.File;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* *
*/ */
@ -20,11 +17,10 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
protected File previous; protected File previous;
protected boolean followLinks; protected boolean followLinks;
/** /**
* *
*/ */
public FileIterator (File root) public FileIterator(final File root)
{ {
super(); super();
@ -42,11 +38,10 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
init(pathnames, null, false); init(pathnames, null, false);
} }
/** /**
* *
*/ */
public FileIterator (File root, String filter, boolean followLinks) public FileIterator(final File root, final String filter, final boolean followLinks)
{ {
super(); super();
@ -64,11 +59,10 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
init(pathnames, filter, followLinks); init(pathnames, filter, followLinks);
} }
/** /**
* *
*/ */
public FileIterator (String pathname, String filter, boolean followLinks) public FileIterator(final String pathname, final String filter, final boolean followLinks)
{ {
super(); super();
@ -86,52 +80,81 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
init(pathnames, filter, followLinks); init(pathnames, filter, followLinks);
} }
/** /**
* *
*/ */
public FileIterator (String[] pathnames, String filter, boolean followLinks) public FileIterator(final String[] pathnames, final String filter, final boolean followLinks)
{ {
super(); super();
init(pathnames, filter, followLinks); init(pathnames, filter, followLinks);
} }
/**
*
*/
public File currentFile()
{
File result;
result = this.currentState().currentFile();
//
return (result);
}
/** /**
* *
*/ */
protected void init (String[] pathnames, String filter, boolean followLinks) protected FileIteratorState currentState()
{ {
setFilter(filter); FileIteratorState result;
this.followLinks = followLinks;
this.previous = null;
this.currentDepth = 0; result = this.get(this.currentDepth);
this.add(new FileIteratorState(pathnames));
shift(); //
return (result);
} }
/** /**
* *
*/ */
public void reset () public int directoryFinalCountdown()
{ {
this.currentDepth = 0; int result;
this.previous = null;
if (this.size() > 0) result = 0;
while (this.hasNext())
{ {
this.get(0).reset(); if (this.next().isDirectory())
FileIteratorState firstState = this.get(0); {
this.removeAllElements(); result += 1;
this.add(firstState); }
} }
shift(); //
return (result);
} }
/**
*
*/
public int fileFinalCountdown()
{
int result;
result = 0;
while (this.hasNext())
{
if (!this.next().isDirectory())
{
result += 1;
}
}
//
return (result);
}
/** /**
* *
@ -153,113 +176,27 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
return (result); return (result);
} }
/** /**
* *
*/ */
public Pattern pattern() public int finalCountdown()
{ {
Pattern result; int result;
result = this.pattern; result = 0;
while (this.next() != null)
//
return(result);
}
/**
*
*/
protected void setFilter(String filter)
{ {
if (filter == null) result += 1;
{
this.pattern = null;
}
else
{
this.pattern = Pattern.compile(filter);
}
}
/**
*
*/
protected FileIteratorState currentState()
{
FileIteratorState result;
result = this.get(this.currentDepth);
//
return(result);
}
/**
*
*/
public File currentFile()
{
File result;
result = this.currentState().currentFile();
//
return(result);
}
/**
*
*/
public void push(File file)
{
if ((file != null) && (file.isDirectory()))
{
this.add(new FileIteratorState(file.listFiles()));
this.currentDepth += 1;
}
}
/**
*
*/
public void pop()
{
this.removeElementAt(this.currentDepth);
this.currentDepth -= 1;
}
/**
*
*/
static public boolean isLink(File file) throws Exception
{
boolean result;
if ((file.exists()) && (file.getCanonicalPath().equals(file.getAbsolutePath())))
{
result = false;
}
else
{
result = true;
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public boolean follow(File file) public boolean follow(final File file)
{ {
boolean result; boolean result;
@ -275,7 +212,8 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
result = false; result = false;
} }
//System.out.println("FOLLOWWWWW=[" + file.getPath() + "][" + this.followLinks + "][" + isLink(file) + "][" + result + "]"); // System.out.println("FOLLOWWWWW=[" + file.getPath() + "][" +
// this.followLinks + "][" + isLink(file) + "][" + result + "]");
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -283,12 +221,142 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
result = false; result = false;
} }
//
return (result);
}
/**
*
*/
@Override
public boolean hasNext()
{
boolean result;
result = this.currentState().hasNext();
// //
return (result); return (result);
} }
/**
*
*/
protected void init(final String[] pathnames, final String filter, final boolean followLinks)
{
setFilter(filter);
this.followLinks = followLinks;
this.previous = null;
this.currentDepth = 0;
this.add(new FileIteratorState(pathnames));
shift();
}
/**
*
*/
@Override
public File next()
{
File result;
result = this.currentState().next();
this.previous = result;
if (result != null)
{
if (result.isDirectory())
{
this.push(result);
}
}
shift();
//
return (result);
}
/**
*
*/
public Pattern pattern()
{
Pattern result;
result = this.pattern;
//
return (result);
}
/**
*
*/
public void pop()
{
this.removeElementAt(this.currentDepth);
this.currentDepth -= 1;
}
/**
*
*/
public void push(final File file)
{
if ((file != null) && (file.isDirectory()))
{
this.add(new FileIteratorState(file.listFiles()));
this.currentDepth += 1;
}
}
/**
*
*/
@Override
public void remove()
{
if (this.previous != null)
{
this.previous.delete();
this.previous = null;
}
}
/**
*
*/
public void reset()
{
this.currentDepth = 0;
this.previous = null;
if (this.size() > 0)
{
this.get(0).reset();
FileIteratorState firstState = this.get(0);
this.removeAllElements();
this.add(firstState);
}
shift();
}
/**
*
*/
protected void setFilter(final String filter)
{
if (filter == null)
{
this.pattern = null;
}
else
{
this.pattern = Pattern.compile(filter);
}
}
/** /**
* Set indexes to the good next item. * Set indexes to the good next item.
@ -334,119 +402,6 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
* *
*/ */
@Override @Override
public boolean hasNext()
{
boolean result;
result = this.currentState().hasNext();
//
return(result);
}
/**
*
*/
@Override
public File next()
{
File result;
result = this.currentState().next();
this.previous = result;
if (result != null)
{
if (result.isDirectory())
{
this.push(result);
}
}
shift();
//
return(result);
}
/**
*
*/
@Override
public void remove()
{
if (this.previous != null)
{
this.previous.delete();
this.previous = null;
}
}
/**
*
*/
public int finalCountdown()
{
int result;
result = 0;
while (this.next() != null)
{
result += 1;
}
//
return(result);
}
/**
*
*/
public int fileFinalCountdown()
{
int result;
result = 0;
while (this.hasNext())
{
if (!this.next().isDirectory())
{
result += 1;
}
}
//
return(result);
}
/**
*
*/
public int directoryFinalCountdown()
{
int result;
result = 0;
while (this.hasNext())
{
if (this.next().isDirectory())
{
result += 1;
}
}
//
return(result);
}
/**
*
*/
public String toString() public String toString()
{ {
String result; String result;
@ -456,4 +411,24 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
// //
return (result); return (result);
} }
/**
*
*/
static public boolean isLink(final File file) throws Exception
{
boolean result;
if ((file.exists()) && (file.getCanonicalPath().equals(file.getAbsolutePath())))
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
} }

View file

@ -3,7 +3,6 @@ package fr.devinsy.util;
import java.io.File; import java.io.File;
import java.util.Iterator; import java.util.Iterator;
/** /**
* Used by FileIterator class. * Used by FileIterator class.
*/ */
@ -12,27 +11,10 @@ public class FileIteratorState implements Iterator<File>
protected File[] files; protected File[] files;
protected int currentIndex; protected int currentIndex;
/**
* Useful for the depth zero, otherwise parent path is lost.
*/
public FileIteratorState (String[] pathnames)
{
// Initialize the state.
this.currentIndex = 0;
this.files = new File[pathnames.length];
for (int pathnameIndex = 0; pathnameIndex < pathnames.length; pathnameIndex++)
{
this.files[pathnameIndex] = new File(pathnames[pathnameIndex]);
}
}
/** /**
* *
*/ */
public FileIteratorState (File[] files) public FileIteratorState(final File[] files)
{ {
// Initialize the state. // Initialize the state.
this.currentIndex = 0; this.currentIndex = 0;
@ -47,44 +29,21 @@ public class FileIteratorState implements Iterator<File>
} }
} }
/** /**
* * Useful for the depth zero, otherwise parent path is lost.
*/ */
public void reset() public FileIteratorState(final String[] pathnames)
{ {
currentIndex = 0; // Initialize the state.
} this.currentIndex = 0;
this.files = new File[pathnames.length];
/** for (int pathnameIndex = 0; pathnameIndex < pathnames.length; pathnameIndex++)
*
*/
protected File[] files()
{ {
File[] result; this.files[pathnameIndex] = new File(pathnames[pathnameIndex]);
result = this.files;
//
return(result);
} }
/**
*
*/
protected int currentIndex()
{
int result;
result = this.currentIndex;
//
return(result);
} }
/** /**
* *
*/ */
@ -105,6 +64,31 @@ public class FileIteratorState implements Iterator<File>
return (result); return (result);
} }
/**
*
*/
protected int currentIndex()
{
int result;
result = this.currentIndex;
//
return (result);
}
/**
*
*/
protected File[] files()
{
File[] result;
result = this.files;
//
return (result);
}
/** /**
* *
@ -114,7 +98,6 @@ public class FileIteratorState implements Iterator<File>
{ {
boolean result; boolean result;
if (this.currentFile() == null) if (this.currentFile() == null)
{ {
result = false; result = false;
@ -128,7 +111,6 @@ public class FileIteratorState implements Iterator<File>
return (result); return (result);
} }
/** /**
* *
*/ */
@ -144,7 +126,6 @@ public class FileIteratorState implements Iterator<File>
return (result); return (result);
} }
/** /**
* *
*/ */
@ -152,4 +133,12 @@ public class FileIteratorState implements Iterator<File>
public void remove() public void remove()
{ {
} }
/**
*
*/
public void reset()
{
currentIndex = 0;
}
} }

View file

@ -7,7 +7,6 @@
*/ */
package fr.devinsy.util; package fr.devinsy.util;
/** /**
* *
* */ * */
@ -16,31 +15,15 @@ public class Fraction
protected long numerator; protected long numerator;
protected long denominator; protected long denominator;
/** /**
* *
*/ */
public Fraction(long numerator, long denominator) public Fraction(final long numerator, final long denominator)
{ {
this.numerator = numerator; this.numerator = numerator;
this.denominator = denominator; this.denominator = denominator;
} }
/**
*
*/
public long numerator()
{
long result;
result = this.numerator;
//
return (result);
}
/** /**
* *
*/ */
@ -54,6 +37,19 @@ public class Fraction
return (result); return (result);
} }
/**
*
*/
public long numerator()
{
long result;
result = this.numerator;
//
return (result);
}
/** /**
* *
*/ */
@ -67,11 +63,50 @@ public class Fraction
return (result); return (result);
} }
/**
*
*/
public String percentageFullString()
{
String result;
result = percentageFullString(this.numerator, this.denominator);
//
return (result);
}
/** /**
* *
*/ */
static public long percentage(long numerator, long denominator) throws Exception public String percentageString()
{
String result;
result = percentageString(this.numerator, this.denominator);
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = this.numerator + "/" + this.denominator;
//
return (result);
}
/**
*
*/
static public long percentage(final long numerator, final long denominator) throws Exception
{ {
long result; long result;
@ -88,11 +123,23 @@ public class Fraction
return (result); return (result);
} }
/**
*
*/
static public String percentageFullString(final long numerator, final long denominator)
{
String result;
result = percentageString(numerator, denominator);
//
return (result);
}
/** /**
* *
*/ */
static public String percentageString(long numerator, long denominator) static public String percentageString(final long numerator, final long denominator)
{ {
String result; String result;
@ -122,64 +169,6 @@ public class Fraction
result = "--%"; result = "--%";
} }
//
return (result);
}
/**
*
*/
public String percentageString()
{
String result;
result = percentageString(this.numerator, this.denominator);
//
return (result);
}
/**
*
*/
static public String percentageFullString(long numerator, long denominator)
{
String result;
result = percentageString(numerator, denominator);
//
return (result);
}
/**
*
*/
public String percentageFullString()
{
String result;
result = percentageFullString(this.numerator, this.denominator);
//
return (result);
}
/**
*
*/
public String toString()
{
String result;
result = this.numerator + "/" + this.denominator;
// //
return (result); return (result);
} }

View file

@ -5,7 +5,6 @@
*/ */
package fr.devinsy.util; package fr.devinsy.util;
/** /**
* *
*/ */
@ -28,11 +27,49 @@ public class InternetProxyConfiguration
this.password = ""; this.password = "";
} }
/**
*
*/
public InternetProxyConfiguration(final String host, final int port, final String login, final String password)
{
//
if (host == null)
{
this.host = "";
}
else
{
this.host = host;
}
//
this.port = port;
//
if (login == null)
{
this.login = "";
}
else
{
this.login = login;
}
//
if (password == null)
{
this.password = "";
}
else
{
this.password = password;
}
}
/** /**
* *
*/ */
public InternetProxyConfiguration (String host, String port, String login, String password) throws Exception public InternetProxyConfiguration(final String host, final String port, final String login, final String password) throws Exception
{ {
// //
if (host == null) if (host == null)
@ -83,47 +120,6 @@ public class InternetProxyConfiguration
} }
} }
/**
*
*/
public InternetProxyConfiguration (String host, int port, String login, String password)
{
//
if (host == null)
{
this.host = "";
}
else
{
this.host = host;
}
//
this.port = port;
//
if (login == null)
{
this.login = "";
}
else
{
this.login = login;
}
//
if (password == null)
{
this.password = "";
}
else
{
this.password = password;
}
}
/** /**
* *
*/ */
@ -137,49 +133,6 @@ public class InternetProxyConfiguration
return (result); return (result);
} }
/**
*
*/
public int port()
{
int result;
result = this.port;
//
return (result);
}
/**
*
*/
public String login()
{
String result;
result = this.login;
//
return (result);
}
/**
*
*/
public String password()
{
String result;
result = this.password;
//
return (result);
}
/** /**
* *
*/ */
@ -200,10 +153,49 @@ public class InternetProxyConfiguration
return (result); return (result);
} }
/**
*
*/
public String login()
{
String result;
result = this.login;
//
return (result);
}
/** /**
* *
*/ */
public String password()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public int port()
{
int result;
result = this.port;
//
return (result);
}
/**
*
*/
@Override
public String toString() public String toString()
{ {
String result; String result;

View file

@ -6,8 +6,8 @@
package fr.devinsy.util; package fr.devinsy.util;
/** /**
* This class defines a simple average manager. For example, it is useful for millisecond. * This class defines a simple average manager. For example, it is useful for
* The maximum value available in input is one day in millisecond. * millisecond. The maximum value available in input is one day in millisecond.
*/ */
public class SimpleAveragemeter public class SimpleAveragemeter
{ {
@ -24,75 +24,15 @@ public class SimpleAveragemeter
this.reset(); this.reset();
} }
/** /**
* *
*/ */
synchronized public void reset() synchronized public void add(final long value)
{
this.sum = 0;
this.cardinal = 0;
}
/**
*
*/
synchronized public long average()
{
long result;
if (cardinal == 0)
{
result = 0;
}
else
{
result = (long) sum/cardinal;
}
//
return(result);
}
/**
*
*/
public long value()
{
long result;
result = this.average();
//
return(result);
}
/**
*
*/
public long cardinal()
{
long result;
result = this.cardinal;
//
return(result);
}
/**
*
*/
synchronized public void add(long value)
{ {
// Manage the sum limit. // Manage the sum limit.
if ((this.sum > Long.MAX_VALUE / 2) && (cardinal % 2 == 0)) if ((this.sum > Long.MAX_VALUE / 2) && (cardinal % 2 == 0))
{ {
this.sum = (long) this.sum /2; this.sum = this.sum / 2;
this.cardinal = this.cardinal / 2; this.cardinal = this.cardinal / 2;
} }
@ -109,10 +49,52 @@ public class SimpleAveragemeter
} }
} }
/**
*
*/
synchronized public long average()
{
long result;
if (cardinal == 0)
{
result = 0;
}
else
{
result = sum / cardinal;
}
//
return (result);
}
/** /**
* *
*/ */
public long cardinal()
{
long result;
result = this.cardinal;
//
return (result);
}
/**
*
*/
synchronized public void reset()
{
this.sum = 0;
this.cardinal = 0;
}
/**
*
*/
@Override
public String toString() public String toString()
{ {
String result; String result;
@ -122,4 +104,17 @@ public class SimpleAveragemeter
// //
return (result); return (result);
} }
/**
*
*/
public long value()
{
long result;
result = this.average();
//
return (result);
}
} }

View file

@ -7,7 +7,6 @@ package fr.devinsy.util;
import java.util.Date; import java.util.Date;
/** /**
* *
*/ */
@ -16,7 +15,6 @@ public class SimpleChronometer
// //
protected long firstTime; protected long firstTime;
/** /**
* *
*/ */
@ -25,16 +23,6 @@ public class SimpleChronometer
this.reset(); this.reset();
} }
/**
*
*/
public void reset()
{
this.firstTime = new Date().getTime();
}
/** /**
* *
*/ */
@ -48,11 +36,55 @@ public class SimpleChronometer
return (result); return (result);
} }
/**
*
*/
public void reset()
{
this.firstTime = new Date().getTime();
}
/**
* TO BE COMPLETED.
*/
static public String humanString(final long interval)
{
String result;
if (interval < 1000)
{
result = interval + "ms";
}
else if (interval < 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else if (interval < 60 * 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else if (interval < 24 * 60 * 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else if (interval < 7 * 24 * 60 * 60 * 1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
else
// if (interval < 7*24*60*60*1000)
{
result = interval / 1000 + "," + interval % 1000 + "s";
}
//
return (result);
}
/** /**
* *
*/ */
static public String shortHumanString(long interval) static public String shortHumanString(final long interval)
{ {
String result; String result;
@ -113,44 +145,6 @@ public class SimpleChronometer
result = interval / (52 * 7 * 24 * 60 * 60 * 1000L) + " années"; result = interval / (52 * 7 * 24 * 60 * 60 * 1000L) + " années";
} }
//
return(result);
}
/**
* TO BE COMPLETED.
*/
static public String humanString(long interval)
{
String result;
if (interval < 1000)
{
result = interval + "ms";
}
else if (interval < 60*1000)
{
result = interval/1000 + "," + interval%1000 + "s";
}
else if (interval < 60*60*1000)
{
result = interval/1000 + "," + interval%1000 + "s";
}
else if (interval < 24*60*60*1000)
{
result = interval/1000 + "," + interval%1000 + "s";
}
else if (interval < 7*24*60*60*1000)
{
result = interval/1000 + "," + interval%1000 + "s";
}
else // if (interval < 7*24*60*60*1000)
{
result = interval/1000 + "," + interval%1000 + "s";
}
// //
return (result); return (result);
} }

View file

@ -11,7 +11,7 @@ public class StacktraceWriter
/** /**
* *
*/ */
static public String toString(Exception exception) static public String toString(final Exception exception)
{ {
String result; String result;

View file

@ -9,9 +9,9 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* This class is a collection of String objects with specific methods. * This class is a collection of String objects with specific methods. It makes
* It makes possible to build a string without any copy. * possible to build a string without any copy. The goal is to optimize the
* The goal is to optimize the building of strings where they are lot of concatenation action. * building of strings where they are lot of concatenation action.
*/ */
public class StringConcatenator extends ArrayList<String> public class StringConcatenator extends ArrayList<String>
{ {
@ -26,29 +26,14 @@ public class StringConcatenator extends ArrayList<String>
super(); super();
} }
/** /**
* *
*/ */
public String getByIndex(int id) public StringConcatenator append(final char character)
{
String result;
result = (String) this.get(id);
//
return (result);
}
/**
*
*/
public StringConcatenator appendln()
{ {
StringConcatenator result; StringConcatenator result;
this.add(LINE_SEPARATOR); this.add(String.valueOf(character));
result = this; result = this;
@ -56,11 +41,10 @@ public class StringConcatenator extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
public StringConcatenator append(String string) public StringConcatenator append(final String string)
{ {
StringConcatenator result; StringConcatenator result;
@ -75,55 +59,10 @@ public class StringConcatenator extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
public StringConcatenator appendln(String string) public StringConcatenator append(final StringConcatenator string)
{
StringConcatenator result;
result = this.append(string).appendln();
//
return(result);
}
/**
*
*/
public StringConcatenator append(char character)
{
StringConcatenator result;
this.add(String.valueOf(character));
result = this;
//
return(result);
}
/**
*
*/
public StringConcatenator appendln(char character)
{
StringConcatenator result;
result = this.append(character).appendln();
//
return(result);
}
/**
*
*/
public StringConcatenator append(StringConcatenator string)
{ {
StringConcatenator result; StringConcatenator result;
@ -144,7 +83,35 @@ public class StringConcatenator extends ArrayList<String>
/** /**
* *
*/ */
public StringConcatenator appendln(StringConcatenator string) public StringConcatenator appendln()
{
StringConcatenator result;
this.add(LINE_SEPARATOR);
result = this;
//
return (result);
}
/**
*
*/
public StringConcatenator appendln(final char character)
{
StringConcatenator result;
result = this.append(character).appendln();
//
return (result);
}
/**
*
*/
public StringConcatenator appendln(final String string)
{ {
StringConcatenator result; StringConcatenator result;
@ -157,14 +124,28 @@ public class StringConcatenator extends ArrayList<String>
/** /**
* *
*/ */
public void writeInto(java.io.Writer out) throws IOException public StringConcatenator appendln(final StringConcatenator string)
{ {
for (int nString = 0; nString < this.size(); nString++) StringConcatenator result;
{
out.write(this.getByIndex(nString)); result = this.append(string).appendln();
}
//
return (result);
} }
/**
*
*/
public String getByIndex(final int id)
{
String result;
result = this.get(id);
//
return (result);
}
/** /**
* *
@ -183,10 +164,10 @@ public class StringConcatenator extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
@Override
public String toString() public String toString()
{ {
String result; String result;
@ -204,11 +185,21 @@ public class StringConcatenator extends ArrayList<String>
return (result); return (result);
} }
/**
*
*/
public void writeInto(final java.io.Writer out) throws IOException
{
for (int nString = 0; nString < this.size(); nString++)
{
out.write(this.getByIndex(nString));
}
}
/** /**
* *
*/ */
static public String toString(String[] strings) static public String toString(final String[] strings)
{ {
String result; String result;
@ -237,11 +228,10 @@ public class StringConcatenator extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
static public String toStringNotNull(String[] strings) static public String toStringNotNull(final String[] strings)
{ {
String result; String result;
@ -256,11 +246,10 @@ public class StringConcatenator extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
static public String toStringWithBracket(String[] strings) static public String toStringWithBracket(final String[] strings)
{ {
String result; String result;
@ -283,77 +272,28 @@ public class StringConcatenator extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
static public String toStringWithCommas(String[] strings) static public String toStringWithBracketNotNull(final String[] strings)
{ {
String result; String result;
if (strings == null) result = toStringWithBrackets(strings);
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings) if (result == null)
{ {
if (merge.size() != 0) result = "";
{
merge.append(",");
}
merge.append(string);
}
result = merge.toString();
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
static public String toStringWithFrenchCommas(String[] strings) static public String toStringWithBrackets(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(", ");
}
merge.append(string);
}
result = merge.toString();
}
//
return(result);
}
/**
*
*/
static public String toStringWithBrackets(String[] strings)
{ {
String result; String result;
@ -377,19 +317,64 @@ public class StringConcatenator extends ArrayList<String>
return (result); return (result);
} }
/**
*
*/
static public String toStringWithCommas(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(",");
}
merge.append(string);
}
result = merge.toString();
}
//
return (result);
}
/** /**
* *
*/ */
static public String toStringWithBracketNotNull(String[] strings) static public String toStringWithFrenchCommas(final String[] strings)
{ {
String result; String result;
result = toStringWithBrackets(strings); if (strings == null)
if (result == null)
{ {
result = ""; result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(", ");
}
merge.append(string);
}
result = merge.toString();
} }
// //

View file

@ -9,9 +9,9 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* This class is a collection of String objects with specific methods. * This class is a collection of String objects with specific methods. It makes
* It makes possible to build a string without any copy. * possible to build a string without any copy. The goal is to optimize the
* The goal is to optimize the building of strings where they are lot of concatenation action. * building of strings where they are lot of concatenation action.
*/ */
public class StringList extends ArrayList<String> public class StringList extends ArrayList<String>
{ {
@ -26,38 +26,22 @@ public class StringList extends ArrayList<String>
super(); super();
} }
/** /**
* *
*/ */
public StringList (int size) public StringList(final int size)
{ {
super(size); super(size);
} }
/** /**
* *
*/ */
public String getByIndex(int id) public StringList append(final char character)
{
String result;
result = (String) this.get(id);
//
return (result);
}
/**
*
*/
public StringList appendln()
{ {
StringList result; StringList result;
this.add(LINE_SEPARATOR); this.add(String.valueOf(character));
result = this; result = this;
@ -65,11 +49,36 @@ public class StringList extends ArrayList<String>
return (result); return (result);
} }
/**
*
*/
public StringList append(final int value)
{
StringList result;
result = this.append(String.valueOf(value));
//
return (result);
}
/**
*
*/
public StringList append(final long value)
{
StringList result;
result = this.append(String.valueOf(value));
//
return (result);
}
/** /**
* Check null parameter before add. * Check null parameter before add.
*/ */
public StringList append(String string) public StringList append(final String string)
{ {
StringList result; StringList result;
@ -84,11 +93,10 @@ public class StringList extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
public StringList append(String ... strings) public StringList append(final String... strings)
{ {
StringList result; StringList result;
@ -106,125 +114,10 @@ public class StringList extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
public StringList appendln(String string) public StringList append(final StringList string)
{
StringList result;
result = this.append(string).appendln();
//
return(result);
}
/**
*
*/
public StringList appendln(String ... strings)
{
StringList result;
result = this.append(strings).appendln();
//
return(result);
}
/**
*
*/
public StringList append(char character)
{
StringList result;
this.add(String.valueOf(character));
result = this;
//
return(result);
}
/**
*
*/
public StringList appendln(char character)
{
StringList result;
result = this.append(character).appendln();
//
return(result);
}
/**
*
*/
public StringList append(int value)
{
StringList result;
result = this.append(String.valueOf(value));
//
return(result);
}
/**
*
*/
public StringList appendln(int value)
{
StringList result;
result = this.append(value).appendln();
//
return(result);
}
/**
*
*/
public StringList append(long value)
{
StringList result;
result = this.append(String.valueOf(value));
//
return(result);
}
/**
*
*/
public StringList appendln(long value)
{
StringList result;
result = this.append(value).appendln();
//
return(result);
}
/**
*
*/
public StringList append(StringList string)
{ {
StringList result; StringList result;
@ -245,7 +138,61 @@ public class StringList extends ArrayList<String>
/** /**
* *
*/ */
public StringList appendln(StringList string) public StringList appendln()
{
StringList result;
this.add(LINE_SEPARATOR);
result = this;
//
return (result);
}
/**
*
*/
public StringList appendln(final char character)
{
StringList result;
result = this.append(character).appendln();
//
return (result);
}
/**
*
*/
public StringList appendln(final int value)
{
StringList result;
result = this.append(value).appendln();
//
return (result);
}
/**
*
*/
public StringList appendln(final long value)
{
StringList result;
result = this.append(value).appendln();
//
return (result);
}
/**
*
*/
public StringList appendln(final String string)
{ {
StringList result; StringList result;
@ -258,14 +205,41 @@ public class StringList extends ArrayList<String>
/** /**
* *
*/ */
public void writeInto(java.io.Writer out) throws IOException public StringList appendln(final String... strings)
{ {
for (int nString = 0; nString < this.size(); nString++) StringList result;
{
out.write(this.getByIndex(nString)); result = this.append(strings).appendln();
}
//
return (result);
} }
/**
*
*/
public StringList appendln(final StringList string)
{
StringList result;
result = this.append(string).appendln();
//
return (result);
}
/**
*
*/
public String getByIndex(final int id)
{
String result;
result = this.get(id);
//
return (result);
}
/** /**
* *
@ -284,28 +258,6 @@ public class StringList extends ArrayList<String>
return (result); return (result);
} }
/**
*
*/
public String toString()
{
String result;
StringBuffer preResult = new StringBuffer(this.lenght());
for (int nString = 0; nString < this.size(); nString++)
{
preResult.append(this.getByIndex(nString));
}
result = new String(preResult);
//
return(result);
}
/** /**
* *
*/ */
@ -324,11 +276,42 @@ public class StringList extends ArrayList<String>
return (result); return (result);
} }
/**
*
*/
@Override
public String toString()
{
String result;
StringBuffer preResult = new StringBuffer(this.lenght());
for (int nString = 0; nString < this.size(); nString++)
{
preResult.append(this.getByIndex(nString));
}
result = new String(preResult);
//
return (result);
}
/** /**
* *
*/ */
static public String multiply(String source, int number) public void writeInto(final java.io.Writer out) throws IOException
{
for (int nString = 0; nString < this.size(); nString++)
{
out.write(this.getByIndex(nString));
}
}
/**
*
*/
static public String multiply(final String source, final int number)
{ {
String result; String result;
@ -344,11 +327,10 @@ public class StringList extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
static public String toString(String[] strings) static public String toString(final String[] strings)
{ {
String result; String result;
@ -377,11 +359,10 @@ public class StringList extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
static public String toStringNotNull(String[] strings) static public String toStringNotNull(final String[] strings)
{ {
String result; String result;
@ -396,11 +377,10 @@ public class StringList extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
static public String toStringWithBracket(String[] strings) static public String toStringWithBracket(final String[] strings)
{ {
String result; String result;
@ -423,77 +403,28 @@ public class StringList extends ArrayList<String>
return (result); return (result);
} }
/** /**
* *
*/ */
static public String toStringWithCommas(String[] strings) static public String toStringWithBracketNotNull(final String[] strings)
{ {
String result; String result;
if (strings == null) result = toStringWithBrackets(strings);
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings) if (result == null)
{ {
if (merge.size() != 0) result = "";
{
merge.append(",");
}
merge.append(string);
}
result = merge.toString();
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
static public String toStringWithFrenchCommas(String[] strings) static public String toStringWithBrackets(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(", ");
}
merge.append(string);
}
result = merge.toString();
}
//
return(result);
}
/**
*
*/
static public String toStringWithBrackets(String[] strings)
{ {
String result; String result;
@ -517,19 +448,64 @@ public class StringList extends ArrayList<String>
return (result); return (result);
} }
/**
*
*/
static public String toStringWithCommas(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(",");
}
merge.append(string);
}
result = merge.toString();
}
//
return (result);
}
/** /**
* *
*/ */
static public String toStringWithBracketNotNull(String[] strings) static public String toStringWithFrenchCommas(final String[] strings)
{ {
String result; String result;
result = toStringWithBrackets(strings); if (strings == null)
if (result == null)
{ {
result = ""; result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(", ");
}
merge.append(string);
}
result = merge.toString();
} }
// //

View file

@ -8,7 +8,6 @@ package fr.devinsy.util;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
/** /**
* *
*/ */
@ -16,7 +15,6 @@ public class StringListWriter extends Writer
{ {
protected StringList out; protected StringList out;
/** /**
* *
*/ */
@ -25,16 +23,14 @@ public class StringListWriter extends Writer
this.out = new StringList(); this.out = new StringList();
} }
/** /**
* *
*/ */
StringListWriter(int size) StringListWriter(final int size)
{ {
this.out = new StringList(size); this.out = new StringList(size);
} }
/* /*
* *
*/ */
@ -56,26 +52,25 @@ public class StringListWriter extends Writer
/* /*
* *
*/ */
@Override public void write(final char c) throws IOException
public void write(char[] cbuf, int off, int len) throws IOException
{
this.out.append(cbuf.toString().substring(off, len));
}
/*
*
*/
public void write(char c) throws IOException
{ {
this.out.append(c); this.out.append(c);
} }
/*
*
*/
@Override
public void write(final char[] cbuf, final int off, final int len) throws IOException
{
this.out.append(cbuf.toString().substring(off, len));
}
/* /*
* *
*/ */
public void write(String string) throws IOException @Override
public void write(final String string) throws IOException
{ {
this.out.append(string); this.out.append(string);
} }

View file

@ -2,10 +2,9 @@ package fr.devinsy.util.cmdexec;
import fr.devinsy.util.StringConcatenator; import fr.devinsy.util.StringConcatenator;
/** /**
* We must use the isOver method on Gobblers because with short tasks the waitFor ends before the Gobbler read. * We must use the isOver method on Gobblers because with short tasks the
* waitFor ends before the Gobbler read.
*/ */
public class CmdExec public class CmdExec
{ {
@ -15,7 +14,6 @@ public class CmdExec
protected String out; protected String out;
protected String err; protected String err;
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
// //
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
@ -23,95 +21,146 @@ public class CmdExec
/** /**
* *
*/ */
public CmdExec (String command) public CmdExec(final String command)
{ {
run(command, StreamGobbler.NONE, StreamGobbler.NONE); run(command, StreamGobbler.NONE, StreamGobbler.NONE);
} }
/** /**
* *
*/ */
public CmdExec (String ... command) public CmdExec(final String... command)
{ {
run(command, StreamGobbler.NONE, StreamGobbler.NONE); run(command, StreamGobbler.NONE, StreamGobbler.NONE);
} }
/** /**
* *
*/ */
public CmdExec (String command, int STDOUT, int STDERR) public CmdExec(final String command, final int STDOUT, final int STDERR)
{ {
run(command, STDOUT, STDERR); run(command, STDOUT, STDERR);
} }
/**
*
*/
public CmdExec(final String command, final StreamGobbler outputGobbler, final StreamGobbler errorGobbler)
{
run(command, outputGobbler, errorGobbler);
}
/** /**
* *
*/ */
public CmdExec (String[] command, int STDOUT, int STDERR) public CmdExec(final String[] command, final int STDOUT, final int STDERR)
{ {
run(command, STDOUT, STDERR); run(command, STDOUT, STDERR);
} }
/** /**
* *
*/ */
public CmdExec (String command, StreamGobbler outputGobbler, StreamGobbler errorGobbler) public CmdExec(final String[] command, final StreamGobbler outputGobbler, final StreamGobbler errorGobbler)
{ {
run(command, outputGobbler, errorGobbler); run(command, outputGobbler, errorGobbler);
} }
/**
*
*/
public CmdExec (String[] command, StreamGobbler outputGobbler, StreamGobbler errorGobbler)
{
run (command, outputGobbler, errorGobbler);
}
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
// //
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
/** /**
* *
* @return
*/ */
public int run (String command, int STDOUT, int STDERR) public String getErrStream()
{ {
int result; String result;
result = run (command, result = this.err;
new StreamGobbler ("OUTPUT", STDOUT),
new StreamGobbler ("ERROR", STDERR));
// //
return (result); return (result);
} }
/**
// *
public int run (String[] command, int STDOUT, int STDERR) * @return
*/
public int getExitValue()
{ {
int result; int result;
result = run (command, result = this.exitValue;
new StreamGobbler ("OUTPUT", STDOUT),
new StreamGobbler ("ERROR", STDERR)); return (result);
}
/**
*
* @return
*/
public String getOutStream()
{
String result;
result = this.out;
// //
return (result); return (result);
} }
/**
*
*/
public int run(final String command, final int STDOUT, final int STDERR)
{
int result;
result = run(command, new StreamGobbler("OUTPUT", STDOUT), new StreamGobbler("ERROR", STDERR));
//
return (result);
}
/**
*
* @param command
* : not a shell command, it must be a executable program.
* @param outputGobbler
* @param errorGobbler
* @return
*/
public int run(final String command, final StreamGobbler outputGobbler, final StreamGobbler errorGobbler)
{
int result;
logger.info("CmdExec(commande) = [" + command + "]");
String[] commands = command.split("[ \t\n\r\f]");
result = run(commands, outputGobbler, errorGobbler);
//
return (result);
}
//
public int run(final String[] command, final int STDOUT, final int STDERR)
{
int result;
result = run(command, new StreamGobbler("OUTPUT", STDOUT), new StreamGobbler("ERROR", STDERR));
//
return (result);
}
/** /**
* Command: not a shell command, it must be a executable program. * Command: not a shell command, it must be a executable program.
*/ */
public int run (String[] command, StreamGobbler outputGobbler, StreamGobbler errorGobbler) public int run(final String[] command, final StreamGobbler outputGobbler, final StreamGobbler errorGobbler)
{ {
this.exitValue = 0; this.exitValue = 0;
@ -134,14 +183,13 @@ public class CmdExec
errorGobbler.start(); errorGobbler.start();
outputGobbler.start(); outputGobbler.start();
// Any error??? // Any error???
this.exitValue = proc.waitFor(); this.exitValue = proc.waitFor();
logger.info("ExitValue: " + exitValue); logger.info("ExitValue: " + exitValue);
// Sometimes, process ends before Gobblers read its outpout, so we must wait them. // Sometimes, process ends before Gobblers read its outpout, so we
while ((!outputGobbler.isOver ()) || // must wait them.
(!errorGobbler.isOver ())) while ((!outputGobbler.isOver()) || (!errorGobbler.isOver()))
{ {
Thread.sleep(2); Thread.sleep(2);
} }
@ -160,67 +208,40 @@ public class CmdExec
return (this.exitValue); return (this.exitValue);
} }
/** /**
* *
* @param command: not a shell command, it must be a executable program.
* @param outputGobbler
* @param errorGobbler
* @return
*/ */
public int run (String command, StreamGobbler outputGobbler, StreamGobbler errorGobbler) static public String multirun(final String... commands) throws Exception
{
int result;
logger.info ("CmdExec(commande) = [" + command + "]");
String[] commands = command.split("[ \t\n\r\f]");
result = run(commands, outputGobbler, errorGobbler);
//
return(result);
}
/**
*
* @return
*/
public int getExitValue ()
{
int result;
result = this.exitValue;
return (result);
}
/**
*
* @return
*/
public String getOutStream ()
{ {
String result; String result;
result = this.out; result = "";
// boolean ended = false;
return (result); int commandCounter = 0;
} while (!ended)
/**
*
* @return
*/
public String getErrStream ()
{ {
String result; if (commandCounter < commands.length)
{
String command = commands[commandCounter];
result = this.err; if ((command == null) || (command.length() == 0))
{
result = null;
commandCounter += 1;
}
else
{
result += CmdExec.run(command);
commandCounter += 1;
}
}
else
{
ended = true;
result = null;
}
}
// //
return (result); return (result);
@ -232,7 +253,7 @@ public class CmdExec
/** /**
* *
*/ */
static public String run (String command) throws Exception static public String run(final String command) throws Exception
{ {
String result; String result;
@ -242,11 +263,10 @@ public class CmdExec
return (result); return (result);
} }
/** /**
* *
*/ */
static public String run (String ... command) throws Exception static public String run(final String... command) throws Exception
{ {
String result; String result;
@ -256,9 +276,7 @@ public class CmdExec
} }
else else
{ {
CmdExec cmd = new CmdExec (command, CmdExec cmd = new CmdExec(command, StreamGobbler.BUFFER, StreamGobbler.BUFFER);
StreamGobbler.BUFFER,
StreamGobbler.BUFFER);
if (cmd.getExitValue() == 0) if (cmd.getExitValue() == 0)
{ {
@ -267,7 +285,8 @@ public class CmdExec
else else
{ {
logger.error("Command=\"" + StringConcatenator.toStringWithBrackets(command)); logger.error("Command=\"" + StringConcatenator.toStringWithBrackets(command));
logger.error("Command=\"[" + StringConcatenator.toString(command) + "]\n out => [" + cmd.getOutStream() + "]\n " + "err => (" + cmd.getErrStream().length () +")[" + cmd.getErrStream() + "]"); logger.error("Command=\"[" + StringConcatenator.toString(command) + "]\n out => [" + cmd.getOutStream() + "]\n " + "err => (" + cmd.getErrStream().length() + ")["
+ cmd.getErrStream() + "]");
throw new Exception(cmd.getErrStream()); throw new Exception(cmd.getErrStream());
} }
} }
@ -276,78 +295,11 @@ public class CmdExec
return (result); return (result);
} }
/** /**
* Examples: * Examples: setfacl("sudo", "setfacl", "-m", "g:cpm:rwX", "/tmp/toto");
* setfacl("setfacl", "-m", "g:cpm:rwX", "/tmp/toto");
* setfacl("setfacl", "-R", "-m", "g:cpm:rwX", "/tmp/toto");
*/
static public String run (String program, String[] args, int min, int max) throws Exception
{
String result;
//
boolean nullArg = false;
boolean ended = false;
int nArg = 0;
while (!ended)
{
if (nArg >= args.length)
{
ended = true;
nullArg = false;
}
else
{
if (args[nArg] == null)
{
ended = true;
nullArg = true;
}
else
{
nArg += 1;
}
}
}
//
if (program == null)
{
throw new Exception ("Null program parameter detected: [" + program + "].");
}
else if (nullArg)
{
throw new Exception ("Null parameter detected in position " + nArg + " for " + StringConcatenator.toStringWithBrackets(args) + ".");
}
else if ((args.length < min) || (args.length > max))
{
throw new Exception ("Bad number of parameters: " + args.length + " for " + StringConcatenator.toStringWithBrackets(args) + ".");
}
else
{
//
String[] command = new String[args.length + 1];
command[0] = program;
for (nArg = 0; nArg < args.length; nArg++)
{
command[nArg + 1] = args[nArg];
}
result = CmdExec.run (command);
}
//
return(result);
}
/**
* Examples:
* setfacl("sudo", "setfacl", "-m", "g:cpm:rwX", "/tmp/toto");
* setfacl("sudo", "setfacl", "-R", "-m", "g:cpm:rwX", "/tmp/toto"); * setfacl("sudo", "setfacl", "-R", "-m", "g:cpm:rwX", "/tmp/toto");
*/ */
static public String run (String program1, String program2, String[] args, int min, int max) throws Exception static public String run(final String program1, final String program2, final String[] args, final int min, final int max) throws Exception
{ {
String result; String result;
@ -411,40 +363,63 @@ public class CmdExec
return (result); return (result);
} }
/** /**
* * Examples: setfacl("setfacl", "-m", "g:cpm:rwX", "/tmp/toto");
* setfacl("setfacl", "-R", "-m", "g:cpm:rwX", "/tmp/toto");
*/ */
static public String multirun (String ... commands) throws Exception static public String run(final String program, final String[] args, final int min, final int max) throws Exception
{ {
String result; String result;
result = ""; //
boolean nullArg = false;
boolean ended = false; boolean ended = false;
int commandCounter = 0; int nArg = 0;
while (!ended) while (!ended)
{ {
if (commandCounter < commands.length) if (nArg >= args.length)
{
String command = commands[commandCounter];
if ((command == null) || (command.length () == 0))
{
result = null;
commandCounter += 1;
}
else
{
result += CmdExec.run (command);
commandCounter += 1;
}
}
else
{ {
ended = true; ended = true;
result = null; nullArg = false;
} }
else
{
if (args[nArg] == null)
{
ended = true;
nullArg = true;
}
else
{
nArg += 1;
}
}
}
//
if (program == null)
{
throw new Exception("Null program parameter detected: [" + program + "].");
}
else if (nullArg)
{
throw new Exception("Null parameter detected in position " + nArg + " for " + StringConcatenator.toStringWithBrackets(args) + ".");
}
else if ((args.length < min) || (args.length > max))
{
throw new Exception("Bad number of parameters: " + args.length + " for " + StringConcatenator.toStringWithBrackets(args) + ".");
}
else
{
//
String[] command = new String[args.length + 1];
command[0] = program;
for (nArg = 0; nArg < args.length; nArg++)
{
command[nArg + 1] = args[nArg];
}
result = CmdExec.run(command);
} }
// //

View file

@ -5,7 +5,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
/** /**
* *
*/ */
@ -21,8 +20,10 @@ public class StreamGobbler extends Thread
protected String type; protected String type;
protected int streamWay; protected int streamWay;
protected StringBuffer stream; protected StringBuffer stream;
protected boolean isOverStatus; // Important if the caller wants have complete stream in case of very short command.
// Important if the caller wants have complete stream in case of very short
// command.
protected boolean isOverStatus;
/** /**
* *
@ -35,27 +36,12 @@ public class StreamGobbler extends Thread
this.isOverStatus = false; this.isOverStatus = false;
} }
/**
*
* @param type
* @param streamWay
*/
StreamGobbler (String type, int streamWay)
{
this.type = type;
this.streamWay = streamWay;
this.stream = new StringBuffer ();
this.isOverStatus = false;
}
/** /**
* *
* @param is * @param is
* @param type * @param type
*/ */
StreamGobbler (InputStream is, String type) StreamGobbler(final InputStream is, final String type)
{ {
this.is = is; this.is = is;
this.type = type; this.type = type;
@ -64,14 +50,13 @@ public class StreamGobbler extends Thread
this.isOverStatus = false; this.isOverStatus = false;
} }
/** /**
* *
* @param is * @param is
* @param type * @param type
* @param streamWay * @param streamWay
*/ */
StreamGobbler (InputStream is, String type, int streamWay) StreamGobbler(final InputStream is, final String type, final int streamWay)
{ {
this.is = is; this.is = is;
this.type = type; this.type = type;
@ -80,59 +65,19 @@ public class StreamGobbler extends Thread
this.isOverStatus = false; this.isOverStatus = false;
} }
/** /**
* *
* @param is * @param type
* @param streamWay
*/ */
public void setInputStream (InputStream is) StreamGobbler(final String type, final int streamWay)
{ {
this.is = is; this.type = type;
this.streamWay = streamWay;
this.stream = new StringBuffer();
this.isOverStatus = false;
} }
/**
*
*/
public void run ()
{
try
{
InputStreamReader isr = new InputStreamReader (is);
BufferedReader br = new BufferedReader (isr);
String line = null;
if (this.streamWay == NONE)
{
while ((line = br.readLine ()) != null);
}
else if (this.streamWay == PRINT)
{
while ((line = br.readLine ()) != null)
{
System.out.println (type + ">" + line);
}
}
else if (this.streamWay == BUFFER)
{
while ((line = br.readLine ()) != null)
{
stream.append (line + "\n");
}
}
else
{
logger.warn("unknow way for stream");
}
}
catch (IOException ioe)
{
ioe.printStackTrace ();
}
this.isOverStatus = true;
}
/** /**
* *
* @return * @return
@ -154,7 +99,6 @@ public class StreamGobbler extends Thread
return (result); return (result);
} }
/** /**
* *
* @return * @return
@ -168,4 +112,58 @@ public class StreamGobbler extends Thread
// //
return (result); return (result);
} }
/**
*
*/
@Override
public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader buffer = new BufferedReader(isr);
String line = null;
if (this.streamWay == NONE)
{
while ((line = buffer.readLine()) != null)
{
;
}
}
else if (this.streamWay == PRINT)
{
while ((line = buffer.readLine()) != null)
{
System.out.println(type + ">" + line);
}
}
else if (this.streamWay == BUFFER)
{
while ((line = buffer.readLine()) != null)
{
stream.append(line + "\n");
}
}
else
{
logger.warn("unknow way for stream");
}
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
this.isOverStatus = true;
}
/**
*
* @param is
*/
public void setInputStream(final InputStream is)
{
this.is = is;
}
} }

View file

@ -5,7 +5,6 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
/** /**
* *
*/ */
@ -14,7 +13,6 @@ public class Wrapper
static private final Wrapper instance = new Wrapper(); static private final Wrapper instance = new Wrapper();
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Wrapper.class); static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Wrapper.class);
/** /**
* return instance of the controller * return instance of the controller
*/ */
@ -23,29 +21,10 @@ public class Wrapper
return (instance); return (instance);
} }
/** /**
* *
*/ */
static public void wrap (String ressource, PrintWriter output) throws IOException static public StringBuffer wrap(final String ressource) throws IOException
{
logger.info ("Enter");
BufferedReader buf = new BufferedReader (new FileReader (ressource));
String ligne;
while ((ligne = buf.readLine()) != null)
{
output.print (ligne);
}
logger.info ("Exit");
}
/**
*
*/
static public StringBuffer wrap (String ressource) throws IOException
{ {
logger.info("Enter"); logger.info("Enter");
StringBuffer result; StringBuffer result;
@ -63,6 +42,23 @@ public class Wrapper
logger.info("Exit"); logger.info("Exit");
return (result); return (result);
} }
/**
*
*/
static public void wrap(final String ressource, final PrintWriter output) throws IOException
{
logger.info("Enter");
BufferedReader buf = new BufferedReader(new FileReader(ressource));
String ligne;
while ((ligne = buf.readLine()) != null)
{
output.print(ligne);
}
logger.info("Exit");
}
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -1,21 +1,18 @@
package fr.devinsy.util.unix; package fr.devinsy.util.unix;
import java.io.*; import java.io.File;
/** /**
* *
*/ */
public class CachedFile public class CachedFile
{ {
static private org.apache.log4j.Logger logger; public enum Status
static
{ {
logger = org.apache.log4j.Logger.getLogger (CachedFile.class); NOT_LOAD, EXPIRED, UPDATED
} }
public enum Status {NOT_LOAD, EXPIRED, UPDATED}; static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(CachedFile.class);
protected String sourceName; protected String sourceName;
protected long sourceTime; protected long sourceTime;
@ -24,14 +21,13 @@ public class CachedFile
/** /**
* *
*/ */
public CachedFile (String fileName) public CachedFile(final String fileName)
{ {
this.sourceName = fileName; this.sourceName = fileName;
this.sourceTime = 0; this.sourceTime = 0;
this.status = Status.NOT_LOAD; this.status = Status.NOT_LOAD;
} }
/** /**
* *
*/ */
@ -62,7 +58,6 @@ public class CachedFile
return (result); return (result);
} }
/** /**
* *
*/ */
@ -87,6 +82,13 @@ public class CachedFile
return (result); return (result);
} }
/**
*
*/
public void setNotLoad()
{
this.status = Status.NOT_LOAD;
}
/** /**
* *
@ -105,15 +107,6 @@ public class CachedFile
this.status = Status.UPDATED; this.status = Status.UPDATED;
} }
} }
/**
*
*/
public void setNotLoad ()
{
this.status = Status.NOT_LOAD;
}
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -2,13 +2,13 @@ package fr.devinsy.util.unix;
import java.util.Vector; import java.util.Vector;
/** /**
* *
*/ */
public class EtcGroupFile extends CachedFile public class EtcGroupFile extends CachedFile
{ {
//static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (EtcGroupFile.class); // static private org.apache.log4j.Logger logger =
// org.apache.log4j.Logger.getLogger (EtcGroupFile.class);
static EtcGroupFile instance = null; static EtcGroupFile instance = null;
protected Groups groups; protected Groups groups;
@ -22,25 +22,115 @@ public class EtcGroupFile extends CachedFile
this.groups = null; this.groups = null;
} }
/*
/**
* *
*/ */
static public EtcGroupFile instance () public boolean contains(final String name)
{ {
EtcGroupFile result; boolean result;
if (EtcGroupFile.instance == null) Groups groups = updatedGroups();
if (groups == null)
{ {
EtcGroupFile.instance = new EtcGroupFile (); result = false;
}
else
{
result = groups.contains(name);
} }
result = EtcGroupFile.instance;
// //
return (result); return (result);
} }
/**
*
*/
public Group get(final int gid)
{
Group result;
Groups groups = updatedGroups();
if (groups == null)
{
result = null;
}
else
{
result = groups.getByGid(gid);
}
//
return (result);
}
/**
*
*/
public Group get(final String name)
{
Group result;
Groups groups = updatedGroups();
if (groups == null)
{
result = null;
}
else
{
result = groups.getByName(name);
}
//
return (result);
}
/**
*
*/
public Vector<String> getLoginGroups(final String login)
{
Vector<String> result;
Groups groups = updatedGroups();
result = groups.getLoginGroups(login);
//
return (result);
}
/**
*
*/
public String getLoginGroupsString(final String login)
{
String result;
groups = updatedGroups();
result = groups.getLoginGroupsString(login);
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = this.groups.toString();
//
return (result);
}
/** /**
* *
@ -69,116 +159,19 @@ public class EtcGroupFile extends CachedFile
return (result); return (result);
} }
/** /**
* *
*/ */
public Group get (String name) static public EtcGroupFile instance()
{ {
Group result; EtcGroupFile result;
Groups groups = updatedGroups (); if (EtcGroupFile.instance == null)
if (groups == null)
{ {
result = null; EtcGroupFile.instance = new EtcGroupFile();
}
else
{
result = groups.getByName (name);
} }
// result = EtcGroupFile.instance;
return (result);
}
/**
*
*/
public Group get (int gid)
{
Group result;
Groups groups = updatedGroups ();
if (groups == null)
{
result = null;
}
else
{
result = groups.getByGid (gid);
}
//
return (result);
}
/*
*
*/
public boolean contains (String name)
{
boolean result;
Groups groups = updatedGroups ();
if (groups == null)
{
result = false;
}
else
{
result = groups.contains (name);
}
//
return (result);
}
/**
*
*/
public Vector<String> getLoginGroups (String login)
{
Vector<String> result;
Groups groups = updatedGroups ();
result = groups.getLoginGroups (login);
//
return (result);
}
/**
*
*/
public String getLoginGroupsString (String login)
{
String result;
groups = updatedGroups ();
result = groups.getLoginGroupsString (login);
//
return (result);
}
/**
*
*/
public String toString ()
{
String result;
result = this.groups.toString ();
// //
return (result); return (result);

View file

@ -4,7 +4,6 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
/** /**
* *
*/ */
@ -12,7 +11,6 @@ public class EtcGroupFileReader
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EtcGroupFileReader.class); static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EtcGroupFileReader.class);
/** /**
* *
*/ */

View file

@ -1,7 +1,5 @@
package fr.devinsy.util.unix; package fr.devinsy.util.unix;
/** /**
* *
*/ */
@ -12,7 +10,6 @@ public class EtcPasswdFile extends CachedFile
static EtcPasswdFile instance = null; static EtcPasswdFile instance = null;
protected Users users; protected Users users;
/** /**
* *
*/ */
@ -22,25 +19,85 @@ public class EtcPasswdFile extends CachedFile
this.users = null; this.users = null;
} }
/*
/**
* *
*/ */
static public EtcPasswdFile instance () public boolean contains(final String login)
{ {
EtcPasswdFile result; boolean result;
if (EtcPasswdFile.instance == null) Users users = updatedUsers();
if (users == null)
{ {
EtcPasswdFile.instance = new EtcPasswdFile (); result = false;
}
else
{
result = users.contains(login);
} }
result = EtcPasswdFile.instance;
// //
return (result); return (result);
} }
/**
*
*/
public User get(final int uid)
{
User result;
Users users = updatedUsers();
if (users == null)
{
result = null;
}
else
{
result = users.getByUid(uid);
}
//
return (result);
}
/**
*
*/
public User get(final String login)
{
User result;
Users users = updatedUsers();
if (users == null)
{
result = null;
}
else
{
result = users.getByLogin(login);
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = this.users.toString();
//
return (result);
}
/** /**
* *
@ -67,7 +124,6 @@ public class EtcPasswdFile extends CachedFile
return (result); return (result);
} }
/** /**
* *
*/ */
@ -86,84 +142,19 @@ public class EtcPasswdFile extends CachedFile
return (result); return (result);
} }
/** /**
* *
*/ */
public User get (String login) static public EtcPasswdFile instance()
{ {
User result; EtcPasswdFile result;
Users users = updatedUsers (); if (EtcPasswdFile.instance == null)
if (users == null)
{ {
result = null; EtcPasswdFile.instance = new EtcPasswdFile();
}
else
{
result = users.getByLogin (login);
} }
// result = EtcPasswdFile.instance;
return (result);
}
/**
*
*/
public User get (int uid)
{
User result;
Users users = updatedUsers ();
if (users == null)
{
result = null;
}
else
{
result = users.getByUid (uid);
}
//
return (result);
}
/*
*
*/
public boolean contains (String login)
{
boolean result;
Users users = updatedUsers ();
if (users == null)
{
result = false;
}
else
{
result = users.contains (login);
}
//
return (result);
}
/**
*
*/
public String toString ()
{
String result;
result = this.users.toString ();
// //
return (result); return (result);

View file

@ -4,7 +4,6 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
/** /**
* *
*/ */
@ -12,7 +11,6 @@ public class EtcPasswdFileReader
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EtcPasswdFileReader.class); static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EtcPasswdFileReader.class);
/** /**
* *
*/ */

View file

@ -2,14 +2,13 @@ package fr.devinsy.util.unix;
import java.util.Vector; import java.util.Vector;
/** /**
* *
*/ */
public class Group public class Group
{ {
//static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (Group.class); // static private org.apache.log4j.Logger logger =
// org.apache.log4j.Logger.getLogger (Group.class);
/* /*
* /usr/include/grp.h * /usr/include/grp.h
@ -24,13 +23,11 @@ public class Group
* }; * };
*/ */
protected String name; protected String name;
protected String password; protected String password;
protected int gid; protected int gid;
protected Vector<String> members; protected Vector<String> members;
/** /**
* *
*/ */
@ -42,12 +39,10 @@ public class Group
this.members = new Vector<String>(); this.members = new Vector<String>();
} }
/** /**
* *
*/ */
public void addMember (String login) public void addMember(final String login)
{ {
if ((login != null) && (login.length() != 0)) if ((login != null) && (login.length() != 0))
{ {
@ -68,6 +63,45 @@ public class Group
return (result); return (result);
} }
/**
*
*/
public Vector<String> getMembers()
{
Vector<String> result;
result = this.members;
//
return (result);
}
/**
*
*/
public String getName()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public String getPassword()
{
String result;
result = this.password;
//
return (result);
}
/** /**
* *
*/ */
@ -81,20 +115,6 @@ public class Group
return (result); return (result);
} }
/**
*
*/
public Vector<String> getMembers ()
{
Vector<String> result;
result = this.members;
//
return (result);
}
/** /**
* *
*/ */
@ -108,20 +128,6 @@ public class Group
return (result); return (result);
} }
/**
*
*/
public String getName ()
{
String result;
result = this.name;
//
return (result);
}
/** /**
* *
*/ */
@ -151,20 +157,7 @@ public class Group
/** /**
* *
*/ */
public String getPassword () public void setGid(final int gid)
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public void setGid (int gid)
{ {
this.gid = gid; this.gid = gid;
} }
@ -172,7 +165,7 @@ public class Group
/** /**
* *
*/ */
public void setName (String name) public void setName(final String name)
{ {
this.name = name; this.name = name;
} }
@ -180,7 +173,7 @@ public class Group
/** /**
* *
*/ */
public void setPasswd (String password) public void setPasswd(final String password)
{ {
this.password = password; this.password = password;
} }
@ -188,7 +181,7 @@ public class Group
/** /**
* *
*/ */
public void setPassword (String password) public void setPassword(final String password)
{ {
this.password = password; this.password = password;
} }
@ -196,6 +189,7 @@ public class Group
/** /**
* *
*/ */
@Override
public String toString() public String toString()
{ {
String result; String result;

View file

@ -3,7 +3,6 @@ package fr.devinsy.util.unix;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
/** /**
* *
*/ */
@ -11,8 +10,9 @@ public class Groups extends Vector<Group>
{ {
private static final long serialVersionUID = 5802487312198869603L; private static final long serialVersionUID = 5802487312198869603L;
//static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (Groups.class);
// static private org.apache.log4j.Logger logger =
// org.apache.log4j.Logger.getLogger (Groups.class);
/** /**
* *
@ -22,11 +22,82 @@ public class Groups extends Vector<Group>
super(); super();
} }
/*
*
*/
public boolean contains(final int gid)
{
boolean result;
if (getByGid(gid) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/*
*
*/
public boolean contains(final String name)
{
boolean result;
if (getByName(name) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/** /**
* *
*/ */
public Group getByName (String name) public Group getByGid(final int gid)
{
Group result;
result = null;
boolean ended = false;
Iterator<Group> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
Group group = iterator.next();
if (group.getGid() == gid)
{
ended = true;
result = group;
}
}
else
{
ended = true;
result = null;
}
}
//
return (result);
}
/**
*
*/
public Group getByName(final String name)
{ {
Group result; Group result;
@ -62,86 +133,10 @@ public class Groups extends Vector<Group>
return (result); return (result);
} }
/** /**
* *
*/ */
public Group getByGid (int gid) public Vector<String> getLoginGroups(final String login)
{
Group result;
result = null;
boolean ended = false;
Iterator<Group> iterator = this.iterator ();
while (!ended)
{
if (iterator.hasNext ())
{
Group group = iterator.next ();
if (group.getGid () == gid)
{
ended = true;
result = group;
}
}
else
{
ended = true;
result = null;
}
}
//
return (result);
}
/*
*
*/
public boolean contains (String name)
{
boolean result;
if (getByName (name) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/*
*
*/
public boolean contains (int gid)
{
boolean result;
if (getByGid (gid) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
*
*/
public Vector<String> getLoginGroups (String login)
{ {
Vector<String> result; Vector<String> result;
@ -162,11 +157,10 @@ public class Groups extends Vector<Group>
return (result); return (result);
} }
/** /**
* *
*/ */
public String getLoginGroupsString (String login) public String getLoginGroupsString(final String login)
{ {
String result; String result;
@ -193,10 +187,10 @@ public class Groups extends Vector<Group>
return (result); return (result);
} }
/** /**
* *
*/ */
@Override
public String toString() public String toString()
{ {
String result; String result;

View file

@ -493,8 +493,7 @@ public class Unix
} }
catch (Exception exception) catch (Exception exception)
{ {
throw new Exception("Error running setfacl command for " + StringConcatenator.toStringWithBrackets(args) + ":" + exception.getMessage() + ".", throw new Exception("Error running setfacl command for " + StringConcatenator.toStringWithBrackets(args) + ":" + exception.getMessage() + ".", exception);
exception);
} }
} }

View file

@ -1,12 +1,12 @@
package fr.devinsy.util.unix; package fr.devinsy.util.unix;
/** /**
* *
*/ */
public class User public class User
{ {
//static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (User.class); // static private org.apache.log4j.Logger logger =
// org.apache.log4j.Logger.getLogger (User.class);
/* /*
* /usr/include/pwd.h * /usr/include/pwd.h
@ -32,7 +32,6 @@ public class User
protected String homeDirectory; protected String homeDirectory;
protected String shell; protected String shell;
/** /**
* *
*/ */
@ -47,11 +46,10 @@ public class User
this.shell = null; this.shell = null;
} }
/** /**
* *
*/ */
public User (User user) public User(final User user)
{ {
this.login = user.login(); this.login = user.login();
this.password = user.passwd(); this.password = user.passwd();
@ -62,7 +60,6 @@ public class User
this.shell = user.shell(); this.shell = user.shell();
} }
/** /**
* *
*/ */
@ -76,21 +73,6 @@ public class User
return (result); return (result);
} }
/**
*
*/
public int gid ()
{
int result;
result = this.gid;
//
return (result);
}
/** /**
* *
*/ */
@ -104,21 +86,6 @@ public class User
return (result); return (result);
} }
/**
*
*/
public String homeDirectory ()
{
String result;
result = this.homeDirectory;
//
return (result);
}
/** /**
* *
*/ */
@ -132,21 +99,6 @@ public class User
return (result); return (result);
} }
/**
*
*/
public String login ()
{
String result;
result = this.login;
//
return (result);
}
/** /**
* *
*/ */
@ -160,21 +112,6 @@ public class User
return (result); return (result);
} }
/**
*
*/
public String passwd ()
{
String result;
result = this.password;
//
return (result);
}
/** /**
* *
*/ */
@ -188,7 +125,6 @@ public class User
return (result); return (result);
} }
/** /**
* *
*/ */
@ -202,21 +138,6 @@ public class User
return (result); return (result);
} }
/**
*
*/
public String realName ()
{
String result;
result = this.realName;
//
return (result);
}
/** /**
* *
*/ */
@ -230,21 +151,6 @@ public class User
return (result); return (result);
} }
/**
*
*/
public String shell ()
{
String result;
result = this.shell;
//
return (result);
}
/** /**
* *
*/ */
@ -261,92 +167,149 @@ public class User
/** /**
* *
*/ */
public int uid () public int gid()
{ {
int result; int result;
result = this.uid; result = this.gid;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public void setHomeDirectory (String homeDirectory) public String homeDirectory()
{ {
this.homeDirectory = homeDirectory; String result;
result = this.homeDirectory;
//
return (result);
} }
/**
*
*/
public String login()
{
String result;
result = this.login;
//
return (result);
}
/** /**
* *
*/ */
public void setGid (int gid) public String passwd()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public String realName()
{
String result;
result = this.realName;
//
return (result);
}
/**
*
*/
public void setGid(final int gid)
{ {
this.gid = gid; this.gid = gid;
} }
/**
*
*/
public void setHomeDirectory(final String homeDirectory)
{
this.homeDirectory = homeDirectory;
}
/** /**
* *
*/ */
public void setLogin (String login) public void setLogin(final String login)
{ {
this.login = login; this.login = login;
} }
/** /**
* *
*/ */
public void setPasswd (String password) public void setPasswd(final String password)
{ {
this.password = password; this.password = password;
} }
/** /**
* *
*/ */
public void setPassword (String password) public void setPassword(final String password)
{ {
this.password = password; this.password = password;
} }
/** /**
* *
*/ */
public void setRealName (String realName) public void setRealName(final String realName)
{ {
this.realName = realName; this.realName = realName;
} }
/** /**
* *
*/ */
public void setShell (String shell) public void setShell(final String shell)
{ {
this.shell = shell; this.shell = shell;
} }
/** /**
* *
*/ */
public void setUid (int uid) public void setUid(final int uid)
{ {
this.uid = uid; this.uid = uid;
} }
/**
*
*/
public String shell()
{
String result;
result = this.shell;
//
return (result);
}
/** /**
* *
*/ */
@Override
public String toString() public String toString()
{ {
String result; String result;
@ -356,6 +319,19 @@ public class User
// //
return (result); return (result);
} }
/**
*
*/
public int uid()
{
int result;
result = this.uid;
//
return (result);
}
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -3,15 +3,15 @@ package fr.devinsy.util.unix;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
/** /**
* *
*/ */
public class Users extends Vector<User> public class Users extends Vector<User>
{ {
private static final long serialVersionUID = -7178304512851592399L; private static final long serialVersionUID = -7178304512851592399L;
//static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (Users.class);
// static private org.apache.log4j.Logger logger =
// org.apache.log4j.Logger.getLogger (Users.class);
/** /**
* *
@ -21,11 +21,50 @@ public class Users extends Vector<User>
super(); super();
} }
/*
*
*/
public boolean contains(final int uid)
{
boolean result;
if (getByUid(uid) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/*
*
*/
public boolean contains(final String login)
{
boolean result;
if (getByLogin(login) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/** /**
* *
*/ */
public User getByLogin (String login) public User getByLogin(final String login)
{ {
User result; User result;
@ -61,11 +100,10 @@ public class Users extends Vector<User>
return (result); return (result);
} }
/** /**
* *
*/ */
public User getByUid (int uid) public User getByUid(final int uid)
{ {
User result; User result;
@ -94,52 +132,10 @@ public class Users extends Vector<User>
return (result); return (result);
} }
/*
*
*/
public boolean contains (String login)
{
boolean result;
if (getByLogin (login) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/*
*
*/
public boolean contains (int uid)
{
boolean result;
if (getByUid (uid) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/** /**
* *
*/ */
@Override
public String toString() public String toString()
{ {
String result; String result;

View file

@ -1,13 +1,12 @@
package fr.devinsy.util.unix.acl; package fr.devinsy.util.unix.acl;
/** /**
* *
*/ */
public class Acl public class Acl
{ {
// static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (Acl.class); // static private org.apache.log4j.Logger logger =
// org.apache.log4j.Logger.getLogger (Acl.class);
/* /*
# file: goo39 # file: goo39
@ -36,11 +35,10 @@ public class Acl
protected AclEntries currentAcl; protected AclEntries currentAcl;
protected AclEntries defaultAcl; protected AclEntries defaultAcl;
/** /**
* *
*/ */
public Acl (String filePathname) public Acl(final String filePathname)
{ {
this.filePathname = filePathname; this.filePathname = filePathname;
this.owner = ""; this.owner = "";
@ -49,113 +47,30 @@ public class Acl
this.defaultAcl = new AclEntries(); this.defaultAcl = new AclEntries();
} }
/** /**
* *
*/ */
public String filePathname() public boolean contains(final AclEntry.Type type, final String id)
{
String result;
result = this.filePathname;
//
return(result);
}
/**
*
*/
public String owner()
{
String result;
result = this.owner;
//
return(result);
}
/**
*
*/
public void setOwner(String owner)
{
this.owner = owner;
}
/**
*
*/
public String group()
{
String result;
result = this.group;
//
return(result);
}
/**
*
*/
public void setGroup(String group)
{
this.group = group;
}
/**
*
*/
public AclEntries currentAcl()
{
AclEntries result;
result = this.currentAcl;
//
return(result);
}
/**
*
*/
public AclEntries defaultAcl()
{
AclEntries result;
result = this.defaultAcl;
//
return(result);
}
/**
*
*/
public boolean containsUser(String login)
{ {
boolean result; boolean result;
result = contains(AclEntry.Type.USER, login); if ((this.currentAcl().contains(type, id)) || (this.defaultAcl().contains(type, id)))
{
result = true;
}
else
{
result = false;
}
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public boolean containsGroup(String group) public boolean containsGroup(final String group)
{ {
boolean result; boolean result;
@ -165,11 +80,10 @@ public class Acl
return (result); return (result);
} }
/** /**
* *
*/ */
public boolean containsId(String id) public boolean containsId(final String id)
{ {
boolean result; boolean result;
@ -186,27 +100,99 @@ public class Acl
return (result); return (result);
} }
/** /**
* *
*/ */
public boolean contains(AclEntry.Type type, String id) public boolean containsUser(final String login)
{ {
boolean result; boolean result;
if ((this.currentAcl().contains(type, id)) || result = contains(AclEntry.Type.USER, login);
(this.defaultAcl().contains(type, id)))
{
result = true;
}
else
{
result = false;
}
// //
return (result); return (result);
} }
/**
*
*/
public AclEntries currentAcl()
{
AclEntries result;
result = this.currentAcl;
//
return (result);
}
/**
*
*/
public AclEntries defaultAcl()
{
AclEntries result;
result = this.defaultAcl;
//
return (result);
}
/**
*
*/
public String filePathname()
{
String result;
result = this.filePathname;
//
return (result);
}
/**
*
*/
public String group()
{
String result;
result = this.group;
//
return (result);
}
/**
*
*/
public String owner()
{
String result;
result = this.owner;
//
return (result);
}
/**
*
*/
public void setGroup(final String group)
{
this.group = group;
}
/**
*
*/
public void setOwner(final String owner)
{
this.owner = owner;
}
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -3,14 +3,15 @@ package fr.devinsy.util.unix.acl;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
/** /**
* *
*/ */
public class AclEntries extends Vector<AclEntry> public class AclEntries extends Vector<AclEntry>
{ {
private static final long serialVersionUID = 5802487312198869603L; private static final long serialVersionUID = 5802487312198869603L;
//static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (AclEntries.class);
// static private org.apache.log4j.Logger logger =
// org.apache.log4j.Logger.getLogger (AclEntries.class);
/** /**
* *
@ -20,11 +21,50 @@ public class AclEntries extends Vector<AclEntry>
super(); super();
} }
/*
*
*/
public boolean contains(final AclEntry.Type type, final String id)
{
boolean result;
if (this.get(type, id) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/** /**
* *
*/ */
public AclEntry get (AclEntry.Type type, String id) public boolean containsId(final String id)
{
boolean result;
if ((this.get(AclEntry.Type.USER, id) == null) && (this.get(AclEntry.Type.GROUP, id) == null))
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
*
*/
public AclEntry get(final AclEntry.Type type, final String id)
{ {
AclEntry result; AclEntry result;
@ -53,27 +93,51 @@ public class AclEntries extends Vector<AclEntry>
return (result); return (result);
} }
/**
/*
* *
*/ */
public boolean contains(AclEntry.Type type, String id) public String[] getGroupIds()
{ {
boolean result; String[] result;
if (this.get (type, id) == null) Vector<String> ids = new Vector<String>();
for (AclEntry entry : this)
{ {
result = false; if ((entry.type == AclEntry.Type.GROUP) && (!ids.contains(entry.id())))
}
else
{ {
result = true; ids.add(entry.id());
} }
}
result = (String[]) ids.toArray();
// //
return (result); return (result);
} }
/**
*
*/
public String[] getIds()
{
String[] result;
Vector<String> ids = new Vector<String>();
for (AclEntry entry : this)
{
if (!ids.contains(entry.id()))
{
ids.add(entry.id());
}
}
result = (String[]) ids.toArray();
//
return (result);
}
/** /**
* *
@ -105,80 +169,10 @@ public class AclEntries extends Vector<AclEntry>
return (result); return (result);
} }
/**
*
*/
public String[] getGroupIds ()
{
String[] result;
Vector<String> ids = new Vector<String> ();
for (AclEntry entry : this)
{
if ((entry.type == AclEntry.Type.GROUP) && (!ids.contains(entry.id())))
{
ids.add(entry.id());
}
}
result = (String[]) ids.toArray();
//
return (result);
}
/**
*
*/
public String[] getIds ()
{
String[] result;
Vector<String> ids = new Vector<String> ();
for (AclEntry entry : this)
{
if (!ids.contains(entry.id()))
{
ids.add(entry.id());
}
}
result = (String[]) ids.toArray();
//
return (result);
}
/**
*
*/
public boolean containsId(String id)
{
boolean result;
if ((this.get(AclEntry.Type.USER, id) == null) &&
(this.get(AclEntry.Type.GROUP, id) == null))
{
result = false;
}
else
{
result = true;
}
//
return(result);
}
/** /**
* *
*/ */
@Override
public String toString() public String toString()
{ {
String result; String result;

View file

@ -1,13 +1,12 @@
package fr.devinsy.util.unix.acl; package fr.devinsy.util.unix.acl;
/** /**
* *
*/ */
public class AclEntry public class AclEntry
{ {
//static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (AclEntry.class); // static private org.apache.log4j.Logger logger =
// org.apache.log4j.Logger.getLogger (AclEntry.class);
/* /*
user::rwx user::rwx
@ -19,39 +18,25 @@ public class AclEntry
other::--- other::---
*/ */
public enum Type {NONE, USER, GROUP, MASK, OTHER}; public enum Type
{
NONE, USER, GROUP, MASK, OTHER
};
protected Type type; protected Type type;
protected String id; protected String id;
protected String permission; protected String permission;
/** /**
* *
*/ */
public AclEntry (Type type, String id, String permission) public AclEntry(final Type type, final String id, final String permission)
{ {
this.type = type; this.type = type;
this.id = id; this.id = id;
this.permission = permission; this.permission = permission;
} }
/**
*
*/
public Type type()
{
Type result;
result = this.type;
//
return(result);
}
/** /**
* *
*/ */
@ -65,7 +50,6 @@ public class AclEntry
return (result); return (result);
} }
/** /**
* *
*/ */
@ -79,10 +63,10 @@ public class AclEntry
return (result); return (result);
} }
/** /**
* *
*/ */
@Override
public String toString() public String toString()
{ {
String result; String result;
@ -92,6 +76,19 @@ public class AclEntry
// //
return (result); return (result);
} }
/**
*
*/
public Type type()
{
Type result;
result = this.type;
//
return (result);
}
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -8,7 +8,6 @@ import fr.devinsy.util.StringConcatenator;
import fr.devinsy.util.cmdexec.CmdExec; import fr.devinsy.util.cmdexec.CmdExec;
import fr.devinsy.util.unix.Unix; import fr.devinsy.util.unix.Unix;
/** /**
* *
*/ */
@ -26,71 +25,51 @@ public class AclManager
static final public Pattern DEFAULT_MASK_PATTERN = Pattern.compile("^default:mask:(.*):(.*)$"); static final public Pattern DEFAULT_MASK_PATTERN = Pattern.compile("^default:mask:(.*):(.*)$");
static final public Pattern DEFAULT_OTHER_PATTERN = Pattern.compile("^default:other:(.*):(.*)$"); static final public Pattern DEFAULT_OTHER_PATTERN = Pattern.compile("^default:other:(.*):(.*)$");
/**
*
*/
public static void clearGroup(final String group, final String filePathName) throws Exception
{
if ((group == null) || (group.length() == 0) || (filePathName == null) || (filePathName.length() == 0))
{
throw new Exception("Bad parameters [" + group + "][" + filePathName + "].");
}
else
{
Unix.setfacl("-R", "-L", "-x", "group:" + group, filePathName);
Unix.setfacl("-R", "-L", "-d", "-x", "group:" + group, filePathName);
}
}
/** /**
* *
*/ */
static public void setfacl (String ... args) throws Exception public static void clearId(final String id, final String filePathName) throws Exception
{ {
try clearUser(id, filePathName);
{ clearGroup(id, filePathName);
CmdExec.run(SUDO, "setfacl", args, 1, 5);
} }
catch (Exception exception)
{
throw new Exception ("Error running setfacl command for " + StringConcatenator.toStringWithBrackets(args) + ":" + exception.getMessage() + ".");
}
}
/** /**
* *
*/ */
static public String getAclData (String filePathName) throws Exception public static void clearUser(final String login, final String filePathName) throws Exception
{ {
String result; if ((login == null) || (login.length() == 0) || (filePathName == null) || (filePathName.length() == 0))
try
{ {
logger.info ("Getting Acl data for [" + filePathName + "]."); throw new Exception("Bad parameters [" + login + "][" + filePathName + "].");
result = CmdExec.run (SUDO, "/usr/bin/getfacl", "--no-effective", filePathName);
logger.info ("Acl data got for [" + filePathName + "].");
} }
catch (Exception exception) else
{ {
throw new Exception ("Error getting ACL for [" + filePathName + "].", exception); Unix.setfacl("-R", "-L", "-x", "user:" + login, filePathName);
Unix.setfacl("-R", "-L", "-d", "-x", "user:" + login, filePathName);
} }
//
return(result);
} }
/** /**
* *
*/ */
static public String[] getAclEntryLines (String filePathName) static public Acl getAcl(final String filePathName) throws Exception
{
String[] result;
try
{
result = getAclData(filePathName).split("\n");
}
catch (Exception exception)
{
result = new String[0];
}
//
return (result);
}
/**
*
*/
static public Acl getAcl (String filePathName) throws Exception
{ {
Acl result; Acl result;
@ -116,7 +95,6 @@ public class AclManager
result.setOwner(matcher.group(1)); result.setOwner(matcher.group(1));
} }
for (int nEntry = 3; nEntry < entries.length; nEntry++) for (int nEntry = 3; nEntry < entries.length; nEntry++)
{ {
String entryLine = entries[nEntry]; String entryLine = entries[nEntry];
@ -185,55 +163,69 @@ public class AclManager
return (result); return (result);
} }
/** /**
* *
*/ */
public static boolean isUsed(AclEntry.Type type, String id, String filePath, String[] filePathNames, int depth) throws Exception static public String getAclData(final String filePathName) throws Exception
{ {
boolean result; String result;
result = false; try
boolean ended = false;
int nLine = 0;
while (!ended)
{ {
if (nLine < filePathNames.length) logger.info("Getting Acl data for [" + filePathName + "].");
{ result = CmdExec.run(SUDO, "/usr/bin/getfacl", "--no-effective", filePathName);
String filePathName = filePathNames[nLine]; logger.info("Acl data got for [" + filePathName + "].");
if (isUsed(type, id, filePath + "/" + filePathName, depth))
{
ended = true;
result = true;
} }
else catch (Exception exception)
{ {
nLine += 1; throw new Exception("Error getting ACL for [" + filePathName + "].", exception);
}
}
else
{
ended = true;
result = false;
}
} }
// //
return (result); return (result);
} }
/**
*
*/
static public String[] getAclEntryLines(final String filePathName)
{
String[] result;
try
{
result = getAclData(filePathName).split("\n");
}
catch (Exception exception)
{
result = new String[0];
}
//
return (result);
}
/** /**
* *
*/ */
public static boolean isUsed(AclEntry.Type type, String id, String filePathName, int depth) throws Exception public static boolean isUsed(final AclEntry.Type type, final String id, final String filePathName) throws Exception
{ {
boolean result; boolean result;
if ((type == null) || result = isUsed(type, id, filePathName, 0);
(id == null) || (id.length() == 0) ||
(filePathName == null) || (filePathName.length() == 0) || //
(depth < 0)) return (result);
}
/**
*
*/
public static boolean isUsed(final AclEntry.Type type, final String id, final String filePathName, final int depth) throws Exception
{
boolean result;
if ((type == null) || (id == null) || (id.length() == 0) || (filePathName == null) || (filePathName.length() == 0) || (depth < 0))
{ {
throw new Exception("Bad parameter: [" + type + "][" + id + "][" + filePathName + "][" + depth + "]."); throw new Exception("Bad parameter: [" + type + "][" + id + "][" + filePathName + "][" + depth + "].");
} }
@ -266,25 +258,10 @@ public class AclManager
return (result); return (result);
} }
/** /**
* *
*/ */
public static boolean isUsed(AclEntry.Type type, String id, String filePathName) throws Exception public static boolean isUsed(final AclEntry.Type type, final String id, final String filePath, final String[] filePathNames, final int depth) throws Exception
{
boolean result;
result = isUsed(type, id, filePathName, 0);
//
return (result);
}
/**
*
*/
public static boolean isUsed(String id, String[] filePathNames, int depth) throws Exception
{ {
boolean result; boolean result;
@ -296,7 +273,7 @@ public class AclManager
if (nLine < filePathNames.length) if (nLine < filePathNames.length)
{ {
String filePathName = filePathNames[nLine]; String filePathName = filePathNames[nLine];
if (isUsed(id, filePathName, depth)) if (isUsed(type, id, filePath + "/" + filePathName, depth))
{ {
ended = true; ended = true;
result = true; result = true;
@ -317,17 +294,27 @@ public class AclManager
return (result); return (result);
} }
/**
*
*/
public static boolean isUsed(final String id, final String filePathName) throws Exception
{
boolean result;
result = isUsed(id, filePathName, 0);
//
return (result);
}
/** /**
* *
*/ */
public static boolean isUsed(String id, String filePathName, int depth) throws Exception public static boolean isUsed(final String id, final String filePathName, final int depth) throws Exception
{ {
boolean result; boolean result;
if ((id == null) || (id.length() == 0) || if ((id == null) || (id.length() == 0) || (filePathName == null) || (filePathName.length() == 0) || (depth < 0))
(filePathName == null) || (filePathName.length() == 0) ||
(depth < 0))
{ {
throw new Exception("Bad parameter: [" + id + "][" + filePathName + "][" + depth + "]."); throw new Exception("Bad parameter: [" + id + "][" + filePathName + "][" + depth + "].");
} }
@ -360,65 +347,56 @@ public class AclManager
return (result); return (result);
} }
/** /**
* *
*/ */
public static boolean isUsed(String id, String filePathName) throws Exception public static boolean isUsed(final String id, final String[] filePathNames, final int depth) throws Exception
{ {
boolean result; boolean result;
result = isUsed(id, filePathName, 0); result = false;
boolean ended = false;
int nLine = 0;
while (!ended)
{
if (nLine < filePathNames.length)
{
String filePathName = filePathNames[nLine];
if (isUsed(id, filePathName, depth))
{
ended = true;
result = true;
}
else
{
nLine += 1;
}
}
else
{
ended = true;
result = false;
}
}
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static void clearUser(String login, String filePathName) throws Exception static public void setfacl(final String... args) throws Exception
{ {
if ((login == null) || (login.length() == 0) || try
(filePathName == null) || (filePathName.length() == 0))
{ {
throw new Exception("Bad parameters [" + login + "][" + filePathName + "]."); CmdExec.run(SUDO, "setfacl", args, 1, 5);
} }
else catch (Exception exception)
{ {
Unix.setfacl("-R", "-L", "-x", "user:" + login, filePathName); throw new Exception("Error running setfacl command for " + StringConcatenator.toStringWithBrackets(args) + ":" + exception.getMessage() + ".");
Unix.setfacl("-R", "-L", "-d", "-x", "user:" + login, filePathName);
} }
} }
/**
*
*/
public static void clearGroup(String group, String filePathName) throws Exception
{
if ((group == null) || (group.length() == 0) ||
(filePathName == null) || (filePathName.length() == 0))
{
throw new Exception("Bad parameters [" + group + "][" + filePathName + "].");
}
else
{
Unix.setfacl("-R", "-L", "-x", "group:" + group, filePathName);
Unix.setfacl("-R", "-L", "-d", "-x", "group:" + group, filePathName);
}
}
/**
*
*/
public static void clearId(String id, String filePathName) throws Exception
{
clearUser(id, filePathName);
clearGroup(id, filePathName);
}
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -1,7 +1,3 @@
/**
* XidvcTest.
*/
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -11,10 +7,12 @@ import fr.devinsy.util.cmdexec.StreamGobbler;
/** /**
* *
*/ */
class CmdExecTester { class CmdExecTester
{
static private org.apache.log4j.Logger logger; static private org.apache.log4j.Logger logger;
static { static
{
// Initialize logger. // Initialize logger.
org.apache.log4j.Logger logger = null; org.apache.log4j.Logger logger = null;
@ -40,15 +38,17 @@ class CmdExecTester {
/** /**
* *
*/ */
public static String check(final String title, final StringBuffer source, public static String check(final String title, final StringBuffer source, final String model)
final String model) { {
String result; String result;
if (source.indexOf(model) == -1) { if (source.indexOf(model) == -1)
result = String.format("%-40s -> KO <-", title) + "\nGet:\n" {
+ source + "\nWaiting:\n" + model; result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model;
} else { }
else
{
result = String.format("%-40s [ OK ] ", title); result = String.format("%-40s [ OK ] ", title);
} }
@ -59,11 +59,11 @@ class CmdExecTester {
/** /**
* *
*/ */
public static void main(final String[] args) { public static void main(final String[] args)
{
System.out.println("Automatic test action for CmdExec!"); System.out.println("Automatic test action for CmdExec!");
Matcher m = Pattern.compile("^#\\sowner:\\s([a-z_][a-z0-9_-]*)$") Matcher m = Pattern.compile("^#\\sowner:\\s([a-z_][a-z0-9_-]*)$").matcher("# owner: cpm");
.matcher("# owner: cpm");
m.matches(); m.matches();
// System.out.println("owner=[" + m.matches() + "]"); // System.out.println("owner=[" + m.matches() + "]");
System.out.println("owner=[" + m.groupCount() + "]"); System.out.println("owner=[" + m.groupCount() + "]");
@ -75,19 +75,22 @@ class CmdExecTester {
/** /**
* *
*/ */
public static void test1() { public static void test1()
try { {
try
{
System.out.println("Launch ..."); System.out.println("Launch ...");
// String command = "/bin/sort -r /etc/passwd"; // String command = "/bin/sort -r /etc/passwd";
String[] command = { "/bin/sort", "-r", "/etc/passwd" }; String[] command = { "/bin/sort", "-r", "/etc/passwd" };
CmdExec cmd = new CmdExec(command, StreamGobbler.BUFFER, CmdExec cmd = new CmdExec(command, StreamGobbler.BUFFER, StreamGobbler.BUFFER);
StreamGobbler.BUFFER);
System.out.println("exitVal=[" + cmd.getExitValue() + "]"); System.out.println("exitVal=[" + cmd.getExitValue() + "]");
System.out.println("out=[" + cmd.getOutStream() + "]"); System.out.println("out=[" + cmd.getOutStream() + "]");
System.out.println("err=[" + cmd.getErrStream() + "]"); System.out.println("err=[" + cmd.getErrStream() + "]");
} catch (Exception exception) { }
catch (Exception exception)
{
exception.printStackTrace(); exception.printStackTrace();
logger.info("ERRRO=" + exception); logger.info("ERRRO=" + exception);
} }

View file

@ -1,6 +1,3 @@
import java.io.File; import java.io.File;
import org.apache.log4j.BasicConfigurator; import org.apache.log4j.BasicConfigurator;
@ -10,7 +7,6 @@ import org.apache.log4j.PatternLayout;
import fr.devinsy.util.FileIterator; import fr.devinsy.util.FileIterator;
/** /**
* *
*/ */
@ -34,6 +30,14 @@ public class FileIteratorTester
logger = org.apache.log4j.Logger.getLogger(FileIteratorTester.class.getName()); logger = org.apache.log4j.Logger.getLogger(FileIteratorTester.class.getName());
} }
/**
*
*/
public static void main(final String[] args)
{
test();
}
/** /**
* *
*/ */
@ -61,11 +65,16 @@ public class FileIteratorTester
System.out.println("----"); System.out.println("----");
// FileIterator i = new FileIterator(new File("tests/TestTree")); // FileIterator i = new FileIterator(new File("tests/TestTree"));
FileIterator i = new FileIterator(new File("tests/TestTree/xine.jpg"), null, true); FileIterator i = new FileIterator(new File("tests/TestTree/xine.jpg"), null, true);
//FileIterator i = new FileIterator(new File("/home/cpm/.kde/cache-cpmstar"), ".*cache.*", false); // FileIterator i = new FileIterator(new
//FileIterator i = new FileIterator(new File("tests/TestTree"), ".*dsc.*", false); // File("/home/cpm/.kde/cache-cpmstar"), ".*cache.*", false);
//FileIterator i = new FileIterator(new File("/home/cpm/Images/Photos/")); // FileIterator i = new FileIterator(new File("tests/TestTree"),
//FileIterator i = new FileIterator(new File("/home/cpm/Images/Photos/"), ".*\\.(JPG|jpg)", false); // ".*dsc.*", false);
//FileIterator i = new FileIterator(new File("/home/cpm/Images/Photos/"), ".*anni_moi.*", false); // FileIterator i = new FileIterator(new
// File("/home/cpm/Images/Photos/"));
// FileIterator i = new FileIterator(new
// File("/home/cpm/Images/Photos/"), ".*\\.(JPG|jpg)", false);
// FileIterator i = new FileIterator(new
// File("/home/cpm/Images/Photos/"), ".*anni_moi.*", false);
while (i.hasNext()) while (i.hasNext())
{ {
@ -80,13 +89,4 @@ public class FileIteratorTester
System.out.println("ERROR:" + exception.getMessage()); System.out.println("ERROR:" + exception.getMessage());
} }
} }
/**
*
*/
public static void main (String[] args)
{
test();
}
} }