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.
* *
@ -27,7 +26,7 @@ public class DataFile
/** /**
* *
*/ */
public DataFile () public DataFile()
{ {
this.id = NOID; this.id = NOID;
this.contentId = NOID; this.contentId = NOID;
@ -41,7 +40,21 @@ 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 = contentId;
this.name = name;
this.size = size;
this.data = data;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public DataFile(final String name, final long size, final byte[] data)
{ {
this.id = NOID; this.id = NOID;
this.contentId = NOID; this.contentId = NOID;
@ -55,43 +68,7 @@ public class DataFile
/** /**
* *
*/ */
public DataFile (int contentId, String name, long size, byte[] data) public int contentId()
{
this.id = NOID;
this.contentId = contentId;
this.name = name;
this.size = size;
this.data = data;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public int id ()
{
int result;
result = this.id;
//
return (result);
}
/**
*
*/
public void setId (int id)
{
this.id = id;
}
/**
*
*/
public int contentId ()
{ {
int result; int result;
@ -104,92 +81,7 @@ public class DataFile
/** /**
* *
*/ */
public void setContentId (int contentId) public String creationDate()
{
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;
}
/**
*
*/
public String creationDate ()
{ {
String result; String result;
@ -202,7 +94,67 @@ public class DataFile
/** /**
* *
*/ */
public void setCreationDate (String creationDate) public String creationUser()
{
String result;
result = this.creationUser;
//
return (result);
}
/**
*
*/
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) if (creationDate == null)
{ {
@ -217,20 +169,7 @@ public class DataFile
/** /**
* *
*/ */
public String creationUser () public void setCreationUser(final String creationUser)
{
String result;
result = this.creationUser;
//
return (result);
}
/**
*
*/
public void setCreationUser (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,115 +24,19 @@ 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;
result = (DataFile) super.get (index);
//
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);
if (name.equals(contentFile.name()))
{
ended = true;
result = contentFile;
}
else
{
nDataFile += 1;
}
}
}
}
//
return (result);
}
/**
*
*/
public DataFile getById (int id)
{
DataFile result = null;
boolean ended = false;
int nDataFile = 0;
while (!ended)
{
if (nDataFile >= this.size())
{
ended = true;
result = null;
}
else
{
DataFile contentFile = this.getByIndex (nDataFile);
if (id == contentFile.id())
{
ended = true;
result = contentFile;
}
else
{
nDataFile += 1;
}
}
}
//
return (result);
}
/**
*
*/
public DataFiles getByContentId (int id)
{ {
DataFiles result = new DataFiles(); DataFiles result = new DataFiles();
@ -151,10 +54,102 @@ public class DataFiles extends ArrayList
return (result); return (result);
} }
/**
*
*/
public DataFile getById(final int id)
{
DataFile result = null;
boolean ended = false;
int nDataFile = 0;
while (!ended)
{
if (nDataFile >= this.size())
{
ended = true;
result = null;
}
else
{
DataFile contentFile = this.getByIndex(nDataFile);
if (id == contentFile.id())
{
ended = true;
result = contentFile;
}
else
{
nDataFile += 1;
}
}
}
//
return (result);
}
/** /**
* *
*/ */
public DataFile getByIndex(final int index)
{
DataFile result;
result = super.get(index);
//
return (result);
}
/**
*
*/
public DataFile getByName(final String name)
{
DataFile result = null;
if ((name == null) || (name.equals("")))
{
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 (name.equals(contentFile.name()))
{
ended = true;
result = contentFile;
}
else
{
dataFileIndex += 1;
}
}
}
}
//
return (result);
}
/**
*
*/
@Override
public String toString() public String toString()
{ {
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
@ -162,8 +157,8 @@ public class DataFiles extends ArrayList
for (int nDataFile = 0; nDataFile < this.size(); nDataFile++) for (int nDataFile = 0; nDataFile < this.size(); nDataFile++)
{ {
DataFile contentFile = this.getByIndex(nDataFile); DataFile contentFile = this.getByIndex(nDataFile);
result.append ("== " + contentFile.name() + "\n"); result.append("== " + contentFile.name() + "\n");
result.append ("contentFile " + nDataFile + " - " + contentFile.name() + "\n"); result.append("contentFile " + nDataFile + " - " + contentFile.name() + "\n");
} }
// //

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,11 +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; String result;
@ -45,18 +44,17 @@ public class DateHelper
} }
else else
{ {
result = String.format (EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.MONTH) + 1, time.get(Calendar.YEAR)); result = String.format(AMERICAN_DATE_FORMAT, time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.DAY_OF_MONTH));
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
static public String shortEuropeanFormat (Calendar time) static public String europeanFormat(final Calendar time)
{ {
String result; String result;
@ -66,88 +64,121 @@ public class DateHelper
} }
else else
{ {
result = String.format (SHORT_EUROPEAN_DATE_FORMAT, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.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 String ISOFormat (Calendar time) static public boolean isAmericanFormat(final String date)
{
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;
if (time == null)
{
result = "";
}
else
{
result = String.format (AMERICAN_DATE_FORMAT, time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.DAY_OF_MONTH));
}
//
return (result);
}
/**
*
*/
static public String rawFormat (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 boolean isValidDate (String date)
{ {
boolean result; boolean result;
if ((isEuropeanFormat (date)) || if (date == null)
(isRawFormat (date)) || {
(isISOFormat (date)) || result = false;
(isAmericanFormat (date))) }
else
{
result = date.matches(AMERICAN_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isEuropeanFormat(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches(EUROPEAN_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isISOFormat(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches(ISO_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
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;
if (date == null)
{
result = false;
}
else
{
result = date.matches(RAW_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isValidDate(final String date)
{
boolean result;
if ((isEuropeanFormat(date)) || (isRawFormat(date)) || (isISOFormat(date)) || (isAmericanFormat(date)))
{ {
result = true; result = true;
} }
@ -160,103 +191,19 @@ public class DateHelper
return (result); return (result);
} }
/** /**
* *
*/ */
static public boolean isEuropeanFormat (String date) static public Calendar parseAmericanDate(final String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches (EUROPEAN_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isRawFormat (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;
if (date == null)
{
result = false;
}
else
{
result = date.matches (ISO_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public boolean isAmericanFormat (String date)
{
boolean result;
if (date == null)
{
result = false;
}
else
{
result = date.matches (AMERICAN_DATE_PATTERN);
}
//
return (result);
}
/**
*
*/
static public Calendar parseISODate (String date)
{ {
Calendar result; Calendar result;
Pattern pattern = Pattern.compile (ISO_DATE_PATTERN); Pattern pattern = Pattern.compile(AMERICAN_DATE_PATTERN);
Matcher matcher = pattern.matcher (date); Matcher matcher = pattern.matcher(date);
if ((matcher.find ()) && (matcher.groupCount () == 3)) if ((matcher.find()) && (matcher.groupCount() == 3))
{ {
result = new GregorianCalendar (Integer.parseInt (matcher.group (1)), result = new GregorianCalendar(Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(1)) - 1, Integer.parseInt(matcher.group(2)));
Integer.parseInt (matcher.group (2)) - 1,
Integer.parseInt (matcher.group (3)));
} }
else else
{ {
@ -267,107 +214,28 @@ public class DateHelper
return (result); return (result);
} }
/**
*
*/
static public Calendar parseRawDate (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;
Pattern pattern = Pattern.compile (AMERICAN_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 (1)) - 1,
Integer.parseInt (matcher.group (2)));
}
else
{
result = null;
}
//
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;
if (isEuropeanFormat (date)) if (isEuropeanFormat(date))
{ {
result = parseEuropeanDate (date); result = parseEuropeanDate(date);
} }
else if (isRawFormat (date)) else if (isRawFormat(date))
{ {
result = parseRawDate (date); result = parseRawDate(date);
} }
else if (isISOFormat (date)) else if (isISOFormat(date))
{ {
result = parseISODate (date); result = parseISODate(date);
} }
else if (isAmericanFormat (date)) else if (isAmericanFormat(date))
{ {
result = parseAmericanDate (date); result = parseAmericanDate(date);
} }
else else
{ {
@ -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;
@ -60,32 +29,32 @@ public class Digester
} }
else else
{ {
//byte[] hash = null; // byte[] hash = null;
InputStream source = null; InputStream source = null;
try try
{ {
MessageDigest digester = MessageDigest.getInstance (digestMethod); MessageDigest digester = MessageDigest.getInstance(digestMethod);
source = new FileInputStream (file); source = new FileInputStream(file);
boolean ended = false; boolean ended = false;
int bytesNumber; int bytesNumber;
byte[] buffer = new byte[100*1024]; byte[] buffer = new byte[100 * 1024];
while (!ended) while (!ended)
{ {
bytesNumber = source.read (buffer); bytesNumber = source.read(buffer);
if (bytesNumber == -1) if (bytesNumber == -1)
{ {
ended = true; ended = true;
} }
else else
{ {
digester.update (buffer, 0, bytesNumber); digester.update(buffer, 0, bytesNumber);
} }
} }
byte[] digest = digester.digest (); byte[] digest = digester.digest();
result = humanReadableDigest (digest); result = humanReadableDigest(digest);
} }
catch (java.security.NoSuchAlgorithmException exception) catch (java.security.NoSuchAlgorithmException exception)
{ {
@ -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,18 +4,17 @@ 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.
*/ */
public class FileCopier public class FileCopier
{ {
static final public int BUFFER_SIZE = 4*1024; static final public int BUFFER_SIZE = 4 * 1024;
/** /**
* *
*/ */
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();
@ -39,14 +35,13 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
pathnames[0] = root.getPath(); pathnames[0] = root.getPath();
} }
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();
@ -61,14 +56,13 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
pathnames[0] = root.getPath(); pathnames[0] = root.getPath();
} }
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();
@ -83,55 +77,84 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
pathnames[0] = pathname; pathnames[0] = pathname;
} }
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);
}
/** /**
* *
@ -150,116 +173,30 @@ 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); return (result);
} }
/**
*
*/
@Override
public boolean hasNext()
{
boolean result;
result = this.currentState().hasNext();
//
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.
@ -296,7 +364,7 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
public void shift() public void shift()
{ {
boolean ended = false; boolean ended = false;
while(!ended) while (!ended)
{ {
File next = this.currentFile(); File next = this.currentFile();
@ -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;
@ -454,6 +409,26 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
result = "[depth=" + this.currentDepth + "][index=" + this.get(this.currentDepth).currentIndex() + "/" + this.get(this.currentDepth).files.length + "]"; result = "[depth=" + this.currentDepth + "][index=" + this.get(this.currentDepth).currentIndex() + "/" + this.get(this.currentDepth).files.length + "]";
// //
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);
} }
/** /**
* *
*/ */
@ -102,9 +61,34 @@ 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;
@ -125,10 +108,9 @@ public class FileIteratorState implements Iterator<File>
} }
// //
return(result); return (result);
} }
/** /**
* *
*/ */
@ -141,10 +123,9 @@ public class FileIteratorState implements Iterator<File>
this.currentIndex += 1; this.currentIndex += 1;
// //
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,65 +169,7 @@ public class Fraction
result = "--%"; result = "--%";
} }
// //
return (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);
}
} }

View file

@ -5,7 +5,6 @@
*/ */
package fr.devinsy.util; package fr.devinsy.util;
/** /**
* *
*/ */
@ -20,7 +19,7 @@ public class InternetProxyConfiguration
/** /**
* *
*/ */
public InternetProxyConfiguration () public InternetProxyConfiguration()
{ {
this.host = ""; this.host = "";
this.port = 0; this.port = 0;
@ -28,66 +27,10 @@ public class InternetProxyConfiguration
this.password = ""; this.password = "";
} }
/** /**
* *
*/ */
public InternetProxyConfiguration (String host, String port, String login, String password) throws Exception public InternetProxyConfiguration(final String host, final int port, final String login, final String password)
{
//
if (host == null)
{
this.host = "";
}
else
{
this.host = host;
}
//
if ((port == null) || (port.trim().length() == 0))
{
this.port = 0;
}
else
{
try
{
this.port = Integer.parseInt (port);
}
catch (Exception exception)
{
String errorMessage = "Incorrect PROXY port value.";
throw new Exception (errorMessage, exception);
}
}
//
if (login == null)
{
this.login = "";
}
else
{
this.login = login;
}
//
if (password == null)
{
this.password = "";
}
else
{
this.password = password;
}
}
/**
*
*/
public InternetProxyConfiguration (String host, int port, String login, String password)
{ {
// //
if (host == null) if (host == null)
@ -123,6 +66,59 @@ public class InternetProxyConfiguration
} }
} }
/**
*
*/
public InternetProxyConfiguration(final String host, final String port, final String login, final String password) throws Exception
{
//
if (host == null)
{
this.host = "";
}
else
{
this.host = host;
}
//
if ((port == null) || (port.trim().length() == 0))
{
this.port = 0;
}
else
{
try
{
this.port = Integer.parseInt(port);
}
catch (Exception exception)
{
String errorMessage = "Incorrect PROXY port value.";
throw new Exception(errorMessage, exception);
}
}
//
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);
}
/** /**
* *
*/ */
@ -197,13 +150,52 @@ 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,94 +6,34 @@
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
{ {
// //
protected long sum; protected long sum;
protected long cardinal; protected long cardinal;
protected long MAX_ADD = 1*24*60*60*1000; // One day in millisecond. protected long MAX_ADD = 1 * 24 * 60 * 60 * 1000; // One day in millisecond.
/** /**
* *
*/ */
public SimpleAveragemeter () public 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;
} }
// Add the new value. // Add the new value.
@ -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,25 +15,14 @@ public class SimpleChronometer
// //
protected long firstTime; protected long firstTime;
/** /**
* *
*/ */
public SimpleChronometer () public SimpleChronometer()
{ {
this.reset(); this.reset();
} }
/**
*
*/
public void reset()
{
this.firstTime = new Date().getTime();
}
/** /**
* *
*/ */
@ -45,84 +33,21 @@ public class SimpleChronometer
result = new Date().getTime() - this.firstTime; result = new Date().getTime() - this.firstTime;
// //
return(result); return (result);
} }
/** /**
* *
*/ */
static public String shortHumanString(long interval) public void reset()
{ {
String result; this.firstTime = new Date().getTime();
if (interval < 1000)
{
result = interval + " ms";
} }
else if (interval < 2*1000)
{
result = interval/1000 + " seconde";
}
else if (interval < 60*1000)
{
result = interval/1000 + " secondes";
}
else if (interval < 2*60*1000L)
{
result = interval/(60*1000L) + " minute";
}
else if (interval < 60*60*1000L)
{
result = interval/(60*1000L) + " minutes";
}
else if (interval < 2*60*60*1000L)
{
result = interval/(60*60*1000L) + " heure";
}
else if (interval < 24*60*60*1000L)
{
result = interval/(60*60*1000L) + " heures";
}
else if (interval < 2*24*60*60*1000L)
{
result = interval/(24*60*60*1000L) + " jour";
}
else if (interval < 7*24*60*60*1000L)
{
result = interval/(24*60*60*1000L) + " jours";
}
else if (interval < 2*7*24*60*60*1000L)
{
result = interval/(7*24*60*60*1000L) + " semaine";
}
else if (interval < 30*24*60*60*1000L)
{
result = interval/(7*24*60*60*1000L) + " semaines";
}
else if (interval < 52*7*24*60*60*1000L)
{
result = interval/(30*24*60*60*1000L) + " mois";
}
else if (interval < 2*52*7*24*60*60*1000L)
{
result = interval/(52*7*24*60*60*1000L) + " année";
}
else
{
result = interval/(52*7*24*60*60*1000L) + " années";
}
//
return(result);
}
/** /**
* TO BE COMPLETED. * TO BE COMPLETED.
*/ */
static public String humanString(long interval) static public String humanString(final long interval)
{ {
String result; String result;
@ -130,28 +55,97 @@ public class SimpleChronometer
{ {
result = interval + "ms"; result = interval + "ms";
} }
else if (interval < 60*1000) else if (interval < 60 * 1000)
{ {
result = interval/1000 + "," + interval%1000 + "s"; result = interval / 1000 + "," + interval % 1000 + "s";
} }
else if (interval < 60*60*1000) else if (interval < 60 * 60 * 1000)
{ {
result = interval/1000 + "," + interval%1000 + "s"; result = interval / 1000 + "," + interval % 1000 + "s";
} }
else if (interval < 24*60*60*1000) else if (interval < 24 * 60 * 60 * 1000)
{ {
result = interval/1000 + "," + interval%1000 + "s"; result = interval / 1000 + "," + interval % 1000 + "s";
} }
else if (interval < 7*24*60*60*1000) else if (interval < 7 * 24 * 60 * 60 * 1000)
{ {
result = interval/1000 + "," + interval%1000 + "s"; result = interval / 1000 + "," + interval % 1000 + "s";
} }
else // if (interval < 7*24*60*60*1000) else
// if (interval < 7*24*60*60*1000)
{ {
result = interval/1000 + "," + interval%1000 + "s"; result = interval / 1000 + "," + interval % 1000 + "s";
} }
// //
return(result); return (result);
}
/**
*
*/
static public String shortHumanString(final long interval)
{
String result;
if (interval < 1000)
{
result = interval + " ms";
}
else if (interval < 2 * 1000)
{
result = interval / 1000 + " seconde";
}
else if (interval < 60 * 1000)
{
result = interval / 1000 + " secondes";
}
else if (interval < 2 * 60 * 1000L)
{
result = interval / (60 * 1000L) + " minute";
}
else if (interval < 60 * 60 * 1000L)
{
result = interval / (60 * 1000L) + " minutes";
}
else if (interval < 2 * 60 * 60 * 1000L)
{
result = interval / (60 * 60 * 1000L) + " heure";
}
else if (interval < 24 * 60 * 60 * 1000L)
{
result = interval / (60 * 60 * 1000L) + " heures";
}
else if (interval < 2 * 24 * 60 * 60 * 1000L)
{
result = interval / (24 * 60 * 60 * 1000L) + " jour";
}
else if (interval < 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (24 * 60 * 60 * 1000L) + " jours";
}
else if (interval < 2 * 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (7 * 24 * 60 * 60 * 1000L) + " semaine";
}
else if (interval < 30 * 24 * 60 * 60 * 1000L)
{
result = interval / (7 * 24 * 60 * 60 * 1000L) + " semaines";
}
else if (interval < 52 * 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (30 * 24 * 60 * 60 * 1000L) + " mois";
}
else if (interval < 2 * 52 * 7 * 24 * 60 * 60 * 1000L)
{
result = interval / (52 * 7 * 24 * 60 * 60 * 1000L) + " année";
}
else
{
result = interval / (52 * 7 * 24 * 60 * 60 * 1000L) + " années";
}
//
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>
{ {
@ -21,46 +21,30 @@ public class StringConcatenator extends ArrayList<String>
/** /**
* *
*/ */
public StringConcatenator () public StringConcatenator()
{ {
super(); super();
} }
/** /**
* *
*/ */
public String getByIndex(int id) public StringConcatenator append(final char character)
{ {
String result; StringConcatenator result;
result = (String) this.get(id); this.add(String.valueOf(character));
result = this;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public StringConcatenator appendln() public StringConcatenator append(final String string)
{
StringConcatenator result;
this.add(LINE_SEPARATOR);
result = this;
//
return(result);
}
/**
*
*/
public StringConcatenator append(String string)
{ {
StringConcatenator result; StringConcatenator result;
@ -72,58 +56,13 @@ public class StringConcatenator extends ArrayList<String>
result = this; result = this;
// //
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;
@ -138,33 +77,75 @@ public class StringConcatenator extends ArrayList<String>
result = this; result = this;
// //
return(result); return (result);
} }
/** /**
* *
*/ */
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;
result = this.append(string).appendln(); result = this.append(string).appendln();
// //
return(result); return (result);
} }
/** /**
* *
*/ */
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);
}
/** /**
* *
@ -180,13 +161,13 @@ public class StringConcatenator extends ArrayList<String>
} }
// //
return(result); return (result);
} }
/** /**
* *
*/ */
@Override
public String toString() public String toString()
{ {
String result; String result;
@ -201,14 +182,24 @@ public class StringConcatenator extends ArrayList<String>
result = new String(preResult); result = new String(preResult);
// //
return(result); return (result);
} }
/** /**
* *
*/ */
static public String toString(String[] strings) 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(final String[] strings)
{ {
String result; String result;
@ -234,14 +225,13 @@ 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;
@ -253,14 +243,13 @@ 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;
@ -280,14 +269,58 @@ 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;
result = toStringWithBrackets(strings);
if (result == null)
{
result = "";
}
//
return (result);
}
/**
*
*/
static public String toStringWithBrackets(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
merge.append("[").append(string).append("]");
}
result = merge.toString();
}
//
return (result);
}
/**
*
*/
static public String toStringWithCommas(final String[] strings)
{ {
String result; String result;
@ -313,14 +346,13 @@ public class StringConcatenator extends ArrayList<String>
} }
// //
return(result); return (result);
} }
/** /**
* *
*/ */
static public String toStringWithFrenchCommas(String[] strings) static public String toStringWithFrenchCommas(final String[] strings)
{ {
String result; String result;
@ -346,53 +378,6 @@ public class StringConcatenator extends ArrayList<String>
} }
// //
return(result); return (result);
}
/**
*
*/
static public String toStringWithBrackets(String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
merge.append("[").append(string).append("]");
}
result = merge.toString();
}
//
return(result);
}
/**
*
*/
static public String toStringWithBracketNotNull(String[] strings)
{
String result;
result = toStringWithBrackets(strings);
if (result == null)
{
result = "";
}
//
return(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 StringList extends ArrayList<String> public class StringList extends ArrayList<String>
{ {
@ -21,55 +21,64 @@ public class StringList extends ArrayList<String>
/** /**
* *
*/ */
public StringList () public StringList()
{ {
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; StringList result;
result = (String) this.get(id); this.add(String.valueOf(character));
result = this;
// //
return (result); return (result);
} }
/**
*
*/
public StringList append(final int value)
{
StringList result;
result = this.append(String.valueOf(value));
//
return (result);
}
/** /**
* *
*/ */
public StringList appendln() public StringList append(final long value)
{ {
StringList result; StringList result;
this.add(LINE_SEPARATOR); result = this.append(String.valueOf(value));
result = this;
// //
return(result); 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;
@ -81,14 +90,13 @@ public class StringList extends ArrayList<String>
result = this; result = this;
// //
return(result); return (result);
} }
/** /**
* *
*/ */
public StringList append(String ... strings) public StringList append(final String... strings)
{ {
StringList result; StringList result;
@ -103,128 +111,13 @@ public class StringList extends ArrayList<String>
result = this; result = this;
// //
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;
@ -239,33 +132,114 @@ public class StringList extends ArrayList<String>
result = this; result = this;
// //
return(result); return (result);
} }
/** /**
* *
*/ */
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;
result = this.append(string).appendln(); result = this.append(string).appendln();
// //
return(result); return (result);
} }
/** /**
* *
*/ */
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);
}
/** /**
* *
@ -281,31 +255,9 @@ 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);
}
/** /**
* *
*/ */
@ -321,14 +273,45 @@ public class StringList extends ArrayList<String>
result = this; result = this;
// //
return(result); return (result);
} }
/** /**
* *
*/ */
static public String multiply(String source, int number) @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);
}
/**
*
*/
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;
@ -341,14 +324,13 @@ public class StringList extends ArrayList<String>
result = strings.toString(); result = strings.toString();
// //
return(result); return (result);
} }
/** /**
* *
*/ */
static public String toString(String[] strings) static public String toString(final String[] strings)
{ {
String result; String result;
@ -374,14 +356,13 @@ 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;
@ -393,14 +374,13 @@ 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;
@ -420,14 +400,58 @@ 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;
result = toStringWithBrackets(strings);
if (result == null)
{
result = "";
}
//
return (result);
}
/**
*
*/
static public String toStringWithBrackets(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
merge.append("[").append(string).append("]");
}
result = merge.toString();
}
//
return (result);
}
/**
*
*/
static public String toStringWithCommas(final String[] strings)
{ {
String result; String result;
@ -453,14 +477,13 @@ public class StringList extends ArrayList<String>
} }
// //
return(result); return (result);
} }
/** /**
* *
*/ */
static public String toStringWithFrenchCommas(String[] strings) static public String toStringWithFrenchCommas(final String[] strings)
{ {
String result; String result;
@ -486,53 +509,6 @@ public class StringList extends ArrayList<String>
} }
// //
return(result); return (result);
}
/**
*
*/
static public String toStringWithBrackets(String[] strings)
{
String result;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
merge.append("[").append(string).append("]");
}
result = merge.toString();
}
//
return(result);
}
/**
*
*/
static public String toStringWithBracketNotNull(String[] strings)
{
String result;
result = toStringWithBrackets(strings);
if (result == null)
{
result = "";
}
//
return(result);
} }
} }

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,20 +2,18 @@ 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
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (CmdExec.class); static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(CmdExec.class);
protected int exitValue; protected int exitValue;
protected String out; protected String out;
protected String err; protected String err;
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
// //
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
@ -23,200 +21,60 @@ 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 (String[] command, int STDOUT, int STDERR) public CmdExec(final String command, final StreamGobbler outputGobbler, final StreamGobbler errorGobbler)
{ {
run (command, STDOUT, STDERR); run(command, outputGobbler, errorGobbler);
} }
/** /**
* *
*/ */
public CmdExec (String command, StreamGobbler outputGobbler, StreamGobbler errorGobbler) public CmdExec(final String[] command, final int STDOUT, final int STDERR)
{ {
run (command, outputGobbler, errorGobbler); 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 int run (String command, int STDOUT, int STDERR)
{
int result;
result = run (command,
new StreamGobbler ("OUTPUT", STDOUT),
new StreamGobbler ("ERROR", STDERR));
//
return (result);
}
//
public int run (String[] command, int STDOUT, 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.
*/
public int run (String[] command, StreamGobbler outputGobbler, StreamGobbler errorGobbler)
{
this.exitValue = 0;
logger.info ("CmdExec(commande[]) = [" + StringConcatenator.toString(command) + "]");
logger.info ("CmdExec(commande[]) = [" + StringConcatenator.toStringWithBrackets(command) + "]");
try
{
Runtime rt = Runtime.getRuntime ();
Process proc = rt.exec(command);
// Any error message?
errorGobbler.setInputStream (proc.getErrorStream ());
// Any output?
outputGobbler.setInputStream (proc.getInputStream ());
// Kick them off
errorGobbler.start ();
outputGobbler.start ();
// Any error???
this.exitValue = proc.waitFor ();
logger.info("ExitValue: " + exitValue);
// Sometimes, process ends before Gobblers read its outpout, so we must wait them.
while ((!outputGobbler.isOver ()) ||
(!errorGobbler.isOver ()))
{
Thread.sleep (2);
}
out = outputGobbler.getStream ();
err = errorGobbler.getStream ();
}
catch (Exception exception)
{
this.err = exception.getMessage();
this.exitValue = -77;
exception.printStackTrace ();
}
//
return (this.exitValue);
}
/**
*
* @param command: not a shell command, it must be a executable program.
* @param outputGobbler
* @param errorGobbler
* @return * @return
*/ */
public int run (String command, StreamGobbler outputGobbler, StreamGobbler errorGobbler) public String getErrStream()
{
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;
result = this.out;
//
return (result);
}
/**
*
* @return
*/
public String getErrStream ()
{ {
String result; String result;
@ -226,27 +84,189 @@ public class CmdExec
return (result); return (result);
} }
/**
*
* @return
*/
public int getExitValue()
{
int result;
result = this.exitValue;
return (result);
}
/**
*
* @return
*/
public String getOutStream()
{
String result;
result = this.out;
//
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.
*/
public int run(final String[] command, final StreamGobbler outputGobbler, final StreamGobbler errorGobbler)
{
this.exitValue = 0;
logger.info("CmdExec(commande[]) = [" + StringConcatenator.toString(command) + "]");
logger.info("CmdExec(commande[]) = [" + StringConcatenator.toStringWithBrackets(command) + "]");
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);
// Any error message?
errorGobbler.setInputStream(proc.getErrorStream());
// Any output?
outputGobbler.setInputStream(proc.getInputStream());
// Kick them off
errorGobbler.start();
outputGobbler.start();
// Any error???
this.exitValue = proc.waitFor();
logger.info("ExitValue: " + exitValue);
// Sometimes, process ends before Gobblers read its outpout, so we
// must wait them.
while ((!outputGobbler.isOver()) || (!errorGobbler.isOver()))
{
Thread.sleep(2);
}
out = outputGobbler.getStream();
err = errorGobbler.getStream();
}
catch (Exception exception)
{
this.err = exception.getMessage();
this.exitValue = -77;
exception.printStackTrace();
}
//
return (this.exitValue);
}
/**
*
*/
static public String multirun(final String... commands) throws Exception
{
String result;
result = "";
boolean ended = false;
int commandCounter = 0;
while (!ended)
{
if (commandCounter < commands.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;
result = null;
}
}
//
return (result);
}
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
// //
// //////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////
/** /**
* *
*/ */
static public String run (String command) throws Exception static public String run(final String command) throws Exception
{ {
String result; String result;
result = CmdExec.run(command.split("[ \t\n\r\f]")); result = CmdExec.run(command.split("[ \t\n\r\f]"));
// //
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;
@ -379,19 +331,19 @@ public class CmdExec
// //
if (program1 == null) if (program1 == null)
{ {
throw new Exception ("Null program parameter 1 detected: [" + program1 + "]."); throw new Exception("Null program parameter 1 detected: [" + program1 + "].");
} }
else if (program2 == null) else if (program2 == null)
{ {
throw new Exception ("Null program parameter 2 detected: [" + program2 + "]."); throw new Exception("Null program parameter 2 detected: [" + program2 + "].");
} }
else if (nullArg) else if (nullArg)
{ {
throw new Exception ("Null parameter detected in position " + nArg + " for " + StringConcatenator.toStringWithBrackets(args) + "."); throw new Exception("Null parameter detected in position " + nArg + " for " + StringConcatenator.toStringWithBrackets(args) + ".");
} }
else if ((args.length < min) || (args.length > max)) else if ((args.length < min) || (args.length > max))
{ {
throw new Exception ("Bad number of parameters: " + args.length + " for " + StringConcatenator.toStringWithBrackets(args) + "."); throw new Exception("Bad number of parameters: " + args.length + " for " + StringConcatenator.toStringWithBrackets(args) + ".");
} }
else else
{ {
@ -404,47 +356,70 @@ public class CmdExec
command[nArg + 2] = args[nArg]; command[nArg + 2] = args[nArg];
} }
result = CmdExec.run (command); result = CmdExec.run(command);
} }
// //
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,13 +5,12 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
/** /**
* *
*/ */
public class StreamGobbler extends Thread public class StreamGobbler extends Thread
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (CmdExec.class); static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(CmdExec.class);
static final public int NONE = 0; static final public int NONE = 0;
static final public int PRINT = 1; static final public int PRINT = 1;
@ -21,129 +20,75 @@ 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;
/** /**
* *
*/ */
StreamGobbler () StreamGobbler()
{ {
this.type = ""; this.type = "";
this.streamWay = NONE; this.streamWay = NONE;
this.stream = new StringBuffer (); this.stream = new StringBuffer();
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;
this.streamWay = NONE; this.streamWay = NONE;
this.stream = new StringBuffer (); this.stream = new StringBuffer();
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;
this.streamWay = streamWay; this.streamWay = streamWay;
this.stream = new StringBuffer (); this.stream = new StringBuffer();
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
*/ */
public String getStream () public String getStream()
{ {
String result; String result;
if (this.stream != null) if (this.stream != null)
{ {
result = this.stream.toString (); result = this.stream.toString();
} }
else else
{ {
@ -154,12 +99,11 @@ public class StreamGobbler extends Thread
return (result); return (result);
} }
/** /**
* *
* @return * @return
*/ */
public boolean isOver () public boolean isOver()
{ {
boolean result; boolean result;
@ -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,64 +5,60 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
/** /**
* *
*/ */
public class Wrapper 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
*/ */
public static Wrapper instance () public static Wrapper instance()
{ {
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"); 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");
StringBuffer result; StringBuffer result;
result = new StringBuffer (); result = new StringBuffer();
BufferedReader buf = new BufferedReader (new FileReader (ressource)); BufferedReader buf = new BufferedReader(new FileReader(ressource));
String ligne; String ligne;
while ((ligne = buf.readLine()) != null) while ((ligne = buf.readLine()) != null)
{ {
result.append (ligne + "\n"); result.append(ligne + "\n");
} }
// //
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,18 +21,17 @@ 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;
} }
/** /**
* *
*/ */
protected File getSourceFile () protected File getSourceFile()
{ {
File result; File result;
@ -45,11 +41,11 @@ public class CachedFile
} }
else else
{ {
File source = new File (this.sourceName); File source = new File(this.sourceName);
if (!source.exists ()) if (!source.exists())
{ {
logger.error ("source file defined but not found"); logger.error("source file defined but not found");
result = null; result = null;
} }
else else
@ -62,21 +58,20 @@ public class CachedFile
return (result); return (result);
} }
/** /**
* *
*/ */
protected Status getStatus () protected Status getStatus()
{ {
Status result; Status result;
File source = getSourceFile (); File source = getSourceFile();
if (source == null) if (source == null)
{ {
this.status = Status.NOT_LOAD; this.status = Status.NOT_LOAD;
} }
else if (this.sourceTime != source.lastModified ()) else if (this.sourceTime != source.lastModified())
{ {
this.status = Status.EXPIRED; this.status = Status.EXPIRED;
} }
@ -87,13 +82,20 @@ public class CachedFile
return (result); return (result);
} }
/**
*
*/
public void setNotLoad()
{
this.status = Status.NOT_LOAD;
}
/** /**
* *
*/ */
public void setUpdated () public void setUpdated()
{ {
File source = getSourceFile (); File source = getSourceFile();
if (source == null) if (source == null)
{ {
@ -101,19 +103,10 @@ public class CachedFile
} }
else else
{ {
this.sourceTime = source.lastModified (); this.sourceTime = source.lastModified();
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;
@ -16,50 +16,140 @@ public class EtcGroupFile extends CachedFile
/** /**
* *
*/ */
protected EtcGroupFile () protected EtcGroupFile()
{ {
super ("/etc/group"); super("/etc/group");
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);
}
/** /**
* *
*/ */
protected Groups updatedGroups () public Group get(final String name)
{ {
Groups result; Group result;
if (getStatus () != Status.UPDATED) Groups groups = updatedGroups();
{
this.groups = EtcGroupFileReader.load ();
if (this.groups == null) if (groups == null)
{ {
setNotLoad (); result = null;
} }
else else
{ {
setUpdated (); 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);
}
/**
*
*/
protected Groups updatedGroups()
{
Groups result;
if (getStatus() != Status.UPDATED)
{
this.groups = EtcGroupFileReader.load();
if (this.groups == null)
{
setNotLoad();
}
else
{
setUpdated();
} }
} }
@ -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,19 +4,17 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
/** /**
* *
*/ */
public class EtcGroupFileReader 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);
/** /**
* *
*/ */
static public Groups load () static public Groups load()
{ {
Groups result; Groups result;
@ -24,11 +22,11 @@ public class EtcGroupFileReader
try try
{ {
file = new BufferedReader (new FileReader ("/etc/group")); file = new BufferedReader(new FileReader("/etc/group"));
} }
catch(FileNotFoundException exception) catch (FileNotFoundException exception)
{ {
logger.error ("File not found"); logger.error("File not found");
file = null; file = null;
} }
@ -38,38 +36,38 @@ public class EtcGroupFileReader
} }
else else
{ {
result = new Groups (); result = new Groups();
try try
{ {
String line; String line;
while ((line = file.readLine ()) != null) while ((line = file.readLine()) != null)
{ {
String[] tokens = line.split (":"); String[] tokens = line.split(":");
Group group = new Group (); Group group = new Group();
group.setName (tokens[0]); group.setName(tokens[0]);
group.setPassword (tokens[1]); group.setPassword(tokens[1]);
group.setGid ((new Integer (tokens[2])).intValue ()); group.setGid((new Integer(tokens[2])).intValue());
// Manage the case of empty shell. // Manage the case of empty shell.
if (tokens.length == 4) if (tokens.length == 4)
{ {
String[] tokensBis = tokens[3].split (","); String[] tokensBis = tokens[3].split(",");
for (int tokenCounter = 0; tokenCounter < tokensBis.length; tokenCounter++) for (int tokenCounter = 0; tokenCounter < tokensBis.length; tokenCounter++)
{ {
group.addMember (tokensBis[tokenCounter]); group.addMember(tokensBis[tokenCounter]);
} }
} }
result.add (group); result.add(group);
} }
file.close(); file.close();
} }
catch (java.io.IOException exception) catch (java.io.IOException exception)
{ {
logger.error ("Exception here."); logger.error("Exception here.");
result = null; result = null;
} }
} }

View file

@ -1,64 +1,121 @@
package fr.devinsy.util.unix; package fr.devinsy.util.unix;
/** /**
* *
*/ */
public class EtcPasswdFile extends CachedFile public class EtcPasswdFile extends CachedFile
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (EtcPasswdFile.class); static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EtcPasswdFile.class);
static EtcPasswdFile instance = null; static EtcPasswdFile instance = null;
protected Users users; protected Users users;
/** /**
* *
*/ */
protected EtcPasswdFile () protected EtcPasswdFile()
{ {
super ("/etc/passwd"); super("/etc/passwd");
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);
}
/** /**
* *
*/ */
protected Users update () public User get(final String login)
{ {
Users result; User result;
logger.debug ("updating"); Users users = updatedUsers();
this.users = EtcPasswdFileReader.load ();
if (this.users == null) if (users == null)
{ {
setNotLoad (); result = null;
} }
else else
{ {
setUpdated (); result = users.getByLogin(login);
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = this.users.toString();
//
return (result);
}
/**
*
*/
protected Users update()
{
Users result;
logger.debug("updating");
this.users = EtcPasswdFileReader.load();
if (this.users == null)
{
setNotLoad();
}
else
{
setUpdated();
} }
result = this.users; result = this.users;
@ -67,15 +124,14 @@ public class EtcPasswdFile extends CachedFile
return (result); return (result);
} }
/** /**
* *
*/ */
protected Users updatedUsers () protected Users updatedUsers()
{ {
Users result; Users result;
if (getStatus () != Status.UPDATED) if (getStatus() != Status.UPDATED)
{ {
update(); update();
} }
@ -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,19 +4,17 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
/** /**
* *
*/ */
public class EtcPasswdFileReader 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);
/** /**
* *
*/ */
static public Users load () static public Users load()
{ {
Users result; Users result;
@ -24,11 +22,11 @@ public class EtcPasswdFileReader
try try
{ {
file = new BufferedReader (new FileReader ("/etc/passwd")); file = new BufferedReader(new FileReader("/etc/passwd"));
} }
catch(FileNotFoundException exception) catch (FileNotFoundException exception)
{ {
logger.error ("File not found"); logger.error("File not found");
file = null; file = null;
} }
@ -38,41 +36,41 @@ public class EtcPasswdFileReader
} }
else else
{ {
result = new Users (); result = new Users();
try try
{ {
String line; String line;
while ((line = file.readLine ()) != null) while ((line = file.readLine()) != null)
{ {
String[] tokens = line.split (":"); String[] tokens = line.split(":");
User user = new User (); User user = new User();
user.setLogin (tokens[0]); user.setLogin(tokens[0]);
user.setPassword (tokens[1]); user.setPassword(tokens[1]);
user.setUid ((new Integer (tokens[2])).intValue ()); user.setUid((new Integer(tokens[2])).intValue());
user.setGid ((new Integer (tokens[3])).intValue ()); user.setGid((new Integer(tokens[3])).intValue());
user.setRealName (tokens[4]); user.setRealName(tokens[4]);
user.setHomeDirectory (tokens[5]); user.setHomeDirectory(tokens[5]);
// Manage the case of empty shell. // Manage the case of empty shell.
if (tokens.length == 7) if (tokens.length == 7)
{ {
user.setShell (tokens[6]); user.setShell(tokens[6]);
} }
else else
{ {
user.setShell (""); user.setShell("");
} }
result.add (user); result.add(user);
} }
file.close(); file.close();
} }
catch (java.io.IOException exception) catch (java.io.IOException exception)
{ {
logger.error ("Exception here."); logger.error("Exception here.");
result = null; result = null;
} }
} }

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,41 +23,37 @@ 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;
/** /**
* *
*/ */
public Group () public Group()
{ {
this.name = null; this.name = null;
this.password = null; this.password = null;
this.gid = -1; this.gid = -1;
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))
{ {
this.members.add (login); this.members.add(login);
} }
} }
/** /**
* *
*/ */
public int getGid () public int getGid()
{ {
int result; int result;
@ -71,7 +66,46 @@ public class Group
/** /**
* *
*/ */
public int gid () 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);
}
/**
*
*/
public int gid()
{ {
int result; int result;
@ -84,7 +118,7 @@ public class Group
/** /**
* *
*/ */
public Vector<String> getMembers () public Vector<String> members()
{ {
Vector<String> result; Vector<String> result;
@ -94,25 +128,10 @@ public class Group
return (result); return (result);
} }
/** /**
* *
*/ */
public Vector<String> members () public String name()
{
Vector<String> result;
result = this.members;
//
return (result);
}
/**
*
*/
public String getName ()
{ {
String result; String result;
@ -125,20 +144,7 @@ public class Group
/** /**
* *
*/ */
public String name () public String passwd()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public String passwd ()
{ {
String result; String 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,7 +189,8 @@ public class Group
/** /**
* *
*/ */
public String toString () @Override
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,22 +10,94 @@ 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);
/** /**
* *
*/ */
public Groups () public Groups()
{ {
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;
@ -38,13 +109,13 @@ public class Groups extends Vector<Group>
{ {
result = null; result = null;
boolean ended = false; boolean ended = false;
Iterator<Group> iterator = this.iterator (); Iterator<Group> iterator = this.iterator();
while (!ended) while (!ended)
{ {
if (iterator.hasNext ()) if (iterator.hasNext())
{ {
Group group = iterator.next (); Group group = iterator.next();
if (group.getName ().equals (name)) if (group.getName().equals(name))
{ {
ended = true; ended = true;
result = group; result = group;
@ -62,99 +133,23 @@ 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;
result = new Vector<String> (); result = new Vector<String>();
Iterator<Group> iterator = this.iterator (); Iterator<Group> iterator = this.iterator();
while (iterator.hasNext ()) while (iterator.hasNext())
{ {
Group group = iterator.next (); Group group = iterator.next();
if (group.members ().contains (login)) if (group.members().contains(login))
{ {
result.add (group.getName ()); result.add(group.getName());
} }
} }
@ -162,55 +157,54 @@ 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;
Vector<String> groups = getLoginGroups (login); Vector<String> groups = getLoginGroups(login);
StringBuffer string = new StringBuffer (); StringBuffer string = new StringBuffer();
for (String group : groups) for (String group : groups)
{ {
if (string.length () == 0) if (string.length() == 0)
{ {
string.append (group); string.append(group);
} }
else else
{ {
string.append (","); string.append(",");
string.append (group); string.append(group);
} }
} }
result = string.toString (); result = string.toString();
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public String toString () @Override
public String toString()
{ {
String result; String result;
StringBuffer out = new StringBuffer (); StringBuffer out = new StringBuffer();
Iterator<Group> iterator = this.iterator (); Iterator<Group> iterator = this.iterator();
while (iterator.hasNext ()) while (iterator.hasNext())
{ {
out.append (iterator.next ().toString () + "\n"); out.append(iterator.next().toString() + "\n");
} }
result = out.toString (); result = out.toString();
// //
return (result); return (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,11 +32,10 @@ public class User
protected String homeDirectory; protected String homeDirectory;
protected String shell; protected String shell;
/** /**
* *
*/ */
public User () public User()
{ {
this.login = null; this.login = null;
this.password = null; this.password = null;
@ -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,11 +60,10 @@ public class User
this.shell = user.shell(); this.shell = user.shell();
} }
/** /**
* *
*/ */
public int getGid () public int getGid()
{ {
int result; int result;
@ -76,25 +73,10 @@ public class User
return (result); return (result);
} }
/** /**
* *
*/ */
public int gid () public String getHomeDirectory()
{
int result;
result = this.gid;
//
return (result);
}
/**
*
*/
public String getHomeDirectory ()
{ {
String result; String result;
@ -104,25 +86,10 @@ public class User
return (result); return (result);
} }
/** /**
* *
*/ */
public String homeDirectory () public String getLogin()
{
String result;
result = this.homeDirectory;
//
return (result);
}
/**
*
*/
public String getLogin ()
{ {
String result; String result;
@ -132,25 +99,10 @@ public class User
return (result); return (result);
} }
/** /**
* *
*/ */
public String login () public String getPasswd()
{
String result;
result = this.login;
//
return (result);
}
/**
*
*/
public String getPasswd ()
{ {
String result; String result;
@ -160,11 +112,10 @@ public class User
return (result); return (result);
} }
/** /**
* *
*/ */
public String passwd () public String getPassword()
{ {
String result; String result;
@ -174,25 +125,10 @@ public class User
return (result); return (result);
} }
/** /**
* *
*/ */
public String getPassword () public String getRealName()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public String getRealName ()
{ {
String result; String result;
@ -202,25 +138,10 @@ public class User
return (result); return (result);
} }
/** /**
* *
*/ */
public String realName () public String getShell()
{
String result;
result = this.realName;
//
return (result);
}
/**
*
*/
public String getShell ()
{ {
String result; String result;
@ -230,25 +151,10 @@ public class User
return (result); return (result);
} }
/** /**
* *
*/ */
public String shell () public int getUid()
{
String result;
result = this.shell;
//
return (result);
}
/**
*
*/
public int getUid ()
{ {
int result; int result;
@ -261,93 +167,150 @@ 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);
}
/** /**
* *
*/ */
public String toString () @Override
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,29 +3,68 @@ 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);
/** /**
* *
*/ */
public Users () public Users()
{ {
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;
@ -37,13 +76,13 @@ public class Users extends Vector<User>
{ {
result = null; result = null;
boolean ended = false; boolean ended = false;
Iterator<User> iterator = this.iterator (); Iterator<User> iterator = this.iterator();
while (!ended) while (!ended)
{ {
if (iterator.hasNext ()) if (iterator.hasNext())
{ {
User user = iterator.next (); User user = iterator.next();
if (user.getLogin ().equals (login)) if (user.getLogin().equals(login))
{ {
ended = true; ended = true;
result = user; result = user;
@ -61,23 +100,22 @@ 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;
result = null; result = null;
boolean ended = false; boolean ended = false;
Iterator<User> iterator = this.iterator (); Iterator<User> iterator = this.iterator();
while (!ended) while (!ended)
{ {
if (iterator.hasNext ()) if (iterator.hasNext())
{ {
User user = iterator.next (); User user = iterator.next();
if (user.getUid () == uid) if (user.getUid() == uid)
{ {
ended = true; ended = true;
result = user; result = user;
@ -94,67 +132,25 @@ 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);
}
/** /**
* *
*/ */
public String toString () @Override
public String toString()
{ {
String result; String result;
StringBuffer out; StringBuffer out;
out = new StringBuffer (); out = new StringBuffer();
Iterator<User> iterator = this.iterator (); Iterator<User> iterator = this.iterator();
while (iterator.hasNext ()) while (iterator.hasNext())
{ {
out.append (iterator.next ().toString () + "\n"); out.append(iterator.next().toString() + "\n");
} }
result = out.toString (); result = out.toString();
// //
return (result); return (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,127 +47,43 @@ 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;
return(result); }
else
{
result = false;
} }
//
return (result);
}
/** /**
* *
*/ */
public boolean containsGroup(String group) public boolean containsGroup(final String group)
{ {
boolean result; boolean result;
result = contains(AclEntry.Type.GROUP, group); result = contains(AclEntry.Type.GROUP, group);
// //
return(result); return (result);
} }
/** /**
* *
*/ */
public boolean containsId(String id) public boolean containsId(final String id)
{ {
boolean result; boolean result;
@ -183,29 +97,101 @@ 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,40 +3,80 @@ 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);
/** /**
* *
*/ */
public AclEntries () public AclEntries()
{ {
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;
result = null; result = null;
boolean ended = false; boolean ended = false;
Iterator<AclEntry> iterator = this.iterator (); Iterator<AclEntry> iterator = this.iterator();
while (!ended) while (!ended)
{ {
if (iterator.hasNext ()) if (iterator.hasNext())
{ {
AclEntry entry = iterator.next (); AclEntry entry = iterator.next();
if ((type == entry.type()) && (entry.id ().equals(id))) if ((type == entry.type()) && (entry.id().equals(id)))
{ {
ended = true; ended = true;
result = entry; result = entry;
@ -53,37 +93,61 @@ 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);
}
/** /**
* *
*/ */
public String[] getUserIds () public String[] getUserIds()
{ {
String[] result; String[] result;
// //
Vector<String> ids = new Vector<String> (); Vector<String> ids = new Vector<String>();
for (AclEntry entry : this) for (AclEntry entry : this)
{ {
@ -105,95 +169,25 @@ public class AclEntries extends Vector<AclEntry>
return (result); return (result);
} }
/** /**
* *
*/ */
public String[] getGroupIds () @Override
{ public String toString()
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);
}
/**
*
*/
public String toString ()
{ {
String result; String result;
StringBuffer out; StringBuffer out;
out = new StringBuffer (); out = new StringBuffer();
Iterator<AclEntry> iterator = this.iterator (); Iterator<AclEntry> iterator = this.iterator();
while (iterator.hasNext ()) while (iterator.hasNext())
{ {
out.append (iterator.next ().toString () + "\n"); out.append(iterator.next().toString() + "\n");
} }
result = out.toString (); result = out.toString();
// //
return (result); return (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);
}
/** /**
* *
*/ */
@ -62,10 +47,9 @@ public class AclEntry
result = this.id; result = this.id;
// //
return(result); return (result);
} }
/** /**
* *
*/ */
@ -76,13 +60,13 @@ public class AclEntry
result = this.type.toString() + ":" + this.id + ":" + this.permission; result = this.type.toString() + ":" + this.id + ":" + this.permission;
// //
return(result); return (result);
} }
/** /**
* *
*/ */
@Override
public String toString() public String toString()
{ {
String result; String result;
@ -90,7 +74,20 @@ public class AclEntry
result = permission; result = permission;
// //
return(result); return (result);
}
/**
*
*/
public Type type()
{
Type result;
result = this.type;
//
return (result);
} }
} }

View file

@ -8,13 +8,12 @@ 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;
/** /**
* *
*/ */
public class AclManager public class AclManager
{ {
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (AclManager.class); static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(AclManager.class);
static public final String SUDO = "/usr/bin/sudo"; static public final String SUDO = "/usr/bin/sudo";
static final public Pattern USER_PATTERN = Pattern.compile("^user:(.*):(.*)$"); static final public Pattern USER_PATTERN = Pattern.compile("^user:(.*):(.*)$");
@ -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];
@ -175,7 +153,7 @@ public class AclManager
} }
else else
{ {
throw new Exception ("Unknow ACL entry line pattern for [" + entryLine + "]."); throw new Exception("Unknow ACL entry line pattern for [" + entryLine + "].");
} }
logger.debug("Acl entry decoded: [" + entry.toString() + "]"); logger.debug("Acl entry decoded: [" + entry.toString() + "]");
@ -185,11 +163,105 @@ public class AclManager
return (result); return (result);
} }
/**
*
*/
static public String getAclData(final String filePathName) throws Exception
{
String result;
try
{
logger.info("Getting Acl data for [" + filePathName + "].");
result = CmdExec.run(SUDO, "/usr/bin/getfacl", "--no-effective", filePathName);
logger.info("Acl data got for [" + filePathName + "].");
}
catch (Exception exception)
{
throw new Exception("Error getting ACL for [" + filePathName + "].", exception);
}
//
return (result);
}
/** /**
* *
*/ */
public static boolean isUsed(AclEntry.Type type, String id, String filePath, String[] filePathNames, int depth) throws Exception 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(final AclEntry.Type type, final String id, final String filePathName) throws Exception
{
boolean result;
result = isUsed(type, id, filePathName, 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 + "].");
}
else
{
File file = new File(filePathName);
if (!file.exists())
{
throw new Exception("File does not exist [" + filePathName + "].");
}
else
{
Acl acl = getAcl(filePathName);
if (acl.contains(type, id))
{
result = true;
}
else if ((file.isDirectory()) && (depth > 0))
{
result = isUsed(type, id, filePathName, file.list(), depth - 1);
}
else
{
result = false;
}
}
}
//
return (result);
}
/**
*
*/
public static boolean isUsed(final AclEntry.Type type, final String id, final String filePath, final String[] filePathNames, final int depth) throws Exception
{ {
boolean result; boolean result;
@ -219,41 +291,50 @@ public class AclManager
} }
// //
return(result); return (result);
} }
/** /**
* *
*/ */
public static boolean isUsed(AclEntry.Type type, String id, String filePathName, int depth) throws Exception public static boolean isUsed(final String id, final String filePathName) throws Exception
{ {
boolean result; boolean result;
if ((type == null) || result = isUsed(id, filePathName, 0);
(id == null) || (id.length() == 0) ||
(filePathName == null) || (filePathName.length() == 0) || //
(depth < 0)) return (result);
}
/**
*
*/
public static boolean isUsed(final String id, final String filePathName, final int depth) throws Exception
{ {
throw new Exception("Bad parameter: [" + type + "][" + id + "][" + filePathName + "][" + depth + "]."); boolean result;
if ((id == null) || (id.length() == 0) || (filePathName == null) || (filePathName.length() == 0) || (depth < 0))
{
throw new Exception("Bad parameter: [" + id + "][" + filePathName + "][" + depth + "].");
} }
else else
{ {
File file = new File (filePathName); File file = new File(filePathName);
if (!file.exists()) if (!file.exists())
{ {
throw new Exception ("File does not exist [" + filePathName + "]."); throw new Exception("File does not exist [" + filePathName + "].");
} }
else else
{ {
Acl acl = getAcl(filePathName); Acl acl = getAcl(filePathName);
if (acl.contains(type, id)) if (acl.containsId(id))
{ {
result = true; result = true;
} }
else if ((file.isDirectory()) && (depth > 0)) else if ((file.isDirectory()) && (depth > 0))
{ {
result = isUsed(type, id, filePathName, file.list(), depth - 1); result = isUsed(id, file.list(), depth - 1);
} }
else else
{ {
@ -266,25 +347,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 String id, 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;
@ -313,111 +379,23 @@ public class AclManager
} }
} }
//
return(result);
}
/**
*
*/
public static boolean isUsed(String id, String filePathName, int depth) throws Exception
{
boolean result;
if ((id == null) || (id.length() == 0) ||
(filePathName == null) || (filePathName.length() == 0) ||
(depth < 0))
{
throw new Exception("Bad parameter: [" + id + "][" + filePathName + "][" + depth + "].");
}
else
{
File file = new File (filePathName);
if (!file.exists())
{
throw new Exception ("File does not exist [" + filePathName + "].");
}
else
{
Acl acl = getAcl(filePathName);
if (acl.containsId(id))
{
result = true;
}
else if ((file.isDirectory()) && (depth > 0))
{
result = isUsed(id, file.list(), depth - 1);
}
else
{
result = false;
}
}
}
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static boolean isUsed(String id, String filePathName) throws Exception static public void setfacl(final String... args) throws Exception
{ {
boolean result; try
{
result = isUsed(id, filePathName, 0); CmdExec.run(SUDO, "setfacl", args, 1, 5);
//
return (result);
} }
catch (Exception exception)
/**
*
*/
public static void clearUser(String login, String filePathName) throws Exception
{ {
if ((login == null) || (login.length() == 0) || throw new Exception("Error running setfacl command for " + StringConcatenator.toStringWithBrackets(args) + ":" + exception.getMessage() + ".");
(filePathName == null) || (filePathName.length() == 0))
{
throw new Exception("Bad parameters [" + login + "][" + filePathName + "].");
} }
else
{
Unix.setfacl("-R", "-L", "-x", "user:" + login, filePathName);
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;
/** /**
* *
*/ */
@ -22,16 +18,24 @@ public class FileIteratorTester
{ {
// Initialize logger. // Initialize logger.
BasicConfigurator.configure (); BasicConfigurator.configure();
Logger defaultLogger = org.apache.log4j.Logger.getRootLogger (); Logger defaultLogger = org.apache.log4j.Logger.getRootLogger();
defaultLogger.setLevel (org.apache.log4j.Level.DEBUG); defaultLogger.setLevel(org.apache.log4j.Level.DEBUG);
defaultLogger.removeAllAppenders(); defaultLogger.removeAllAppenders();
defaultLogger.addAppender(new ConsoleAppender(new PatternLayout("%d{ISO8601} - FIT [%-5p] %34.34c.%-25M - %m%n"))); defaultLogger.addAppender(new ConsoleAppender(new PatternLayout("%d{ISO8601} - FIT [%-5p] %34.34c.%-25M - %m%n")));
defaultLogger.debug ("Log initialized."); defaultLogger.debug("Log initialized.");
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();
} }
/** /**
@ -43,8 +47,8 @@ public class FileIteratorTester
try try
{ {
//File f = new File("TestTree/DirectoryOne/titi2"); // File f = new File("TestTree/DirectoryOne/titi2");
//File f = new File("/home/cpm/.kde//cache-cpmstar"); // File f = new File("/home/cpm/.kde//cache-cpmstar");
File f = new File("tests/TestTree/xine.jpg"); File f = new File("tests/TestTree/xine.jpg");
System.out.println("exists=" + f.exists()); System.out.println("exists=" + f.exists());
System.out.println("canonical path = " + f.getCanonicalPath()); System.out.println("canonical path = " + f.getCanonicalPath());
@ -59,34 +63,30 @@ public class FileIteratorTester
System.out.println("list = " + f.list()); System.out.println("list = " + f.list());
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())
{ {
//System.out.println(i.toString()); // System.out.println(i.toString());
System.out.println("File=[" + i.next().getPath() + "]"); System.out.println("File=[" + i.next().getPath() + "]");
} }
i.reset(); i.reset();
System.out.println("Cardinal=" + i.finalCountdown()); System.out.println("Cardinal=" + i.finalCountdown());
} }
catch(Exception exception) catch (Exception exception)
{ {
System.out.println("ERROR:" + exception.getMessage()); System.out.println("ERROR:" + exception.getMessage());
} }
} }
/**
*
*/
public static void main (String[] args)
{
test();
}
} }