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
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
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.enumIdentifier=error
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,240 +5,238 @@
*/
package fr.devinsy.util;
/**
* This class defines a content file.
*
*/
public class DataFile
{
static public int NOID = 0;
static public int DEFAULT_SIZE = 0;
//
protected int id;
protected int contentId;
protected String name;
protected long size;
protected byte[] data;
protected String creationDate;
protected String creationUser;
/**
*
*/
public DataFile ()
{
this.id = NOID;
this.contentId = NOID;
this.name = null;
this.size = DEFAULT_SIZE;
this.data = null;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public DataFile (String name, long size, byte[] data)
{
this.id = NOID;
this.contentId = NOID;
this.name = name;
this.size = size;
this.data = data;
this.creationDate = null;
this.creationUser = null;
}
static public int NOID = 0;
static public int DEFAULT_SIZE = 0;
/**
*
*/
public DataFile (int contentId, String name, long size, byte[] data)
{
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;
result = this.contentId;
//
return (result);
}
/**
*
*/
public void setContentId (int contentId)
{
this.contentId = contentId;
}
/**
*
*/
public String name ()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public void setName (String name)
{
if (name == null)
{
this.name = "";
}
else
{
this.name = name;
}
}
//
protected int id;
protected int contentId;
protected String name;
protected long size;
protected byte[] data;
protected String creationDate;
protected String creationUser;
/**
*
*
*/
public long size ()
public DataFile()
{
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;
this.id = NOID;
this.contentId = NOID;
this.name = null;
this.size = DEFAULT_SIZE;
this.data = null;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public String creationDate ()
public DataFile(final int contentId, final String name, final long size, final byte[] data)
{
String result;
result = this.creationDate;
//
return (result);
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.contentId = NOID;
this.name = name;
this.size = size;
this.data = data;
this.creationDate = null;
this.creationUser = null;
}
/**
*
*/
public void setCreationDate (String creationDate)
public int contentId()
{
if (creationDate == null)
{
this.creationDate = "";
}
else
{
this.creationDate = creationDate;
}
int result;
result = this.contentId;
//
return (result);
}
/**
*
*/
public String creationDate()
{
String result;
result = this.creationDate;
//
return (result);
}
/**
*
*/
public String creationUser ()
public String creationUser()
{
String result;
result = this.creationUser;
//
return (result);
String result;
result = this.creationUser;
//
return (result);
}
/**
*
*/
public void setCreationUser (String creationUser)
public byte[] data()
{
if (creationUser == null)
byte[] result;
result = this.data;
//
return (result);
}
/**
*
*/
public int id()
{
int result;
result = this.id;
//
return (result);
}
/**
*
*/
public String name()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public void setContentId(final int contentId)
{
this.contentId = contentId;
}
/**
*
*/
public void setCreationDate(final String creationDate)
{
if (creationDate == null)
{
this.creationUser = "";
this.creationDate = "";
}
else
{
this.creationUser = creationUser;
this.creationDate = creationDate;
}
}
/**
*
*/
public void setCreationUser(final String creationUser)
{
if (creationUser == null)
{
this.creationUser = "";
}
else
{
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.
*
*/
public class DataFiles extends ArrayList
public class DataFiles extends ArrayList<DataFile>
{
private static final long serialVersionUID = -4584622422555785456L;
/**
*
*
@ -25,115 +24,19 @@ public class DataFiles extends ArrayList
super();
}
/**
*
* @param source
*/
public DataFiles (DataFiles source)
public DataFiles(final DataFiles source)
{
super(source);
}
/**
*
*/
public DataFile getByIndex (int index)
{
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)
public DataFiles getByContentId(final int id)
{
DataFiles result = new DataFiles();
@ -151,10 +54,102 @@ public class DataFiles extends ArrayList
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()
{
StringBuffer result = new StringBuffer();
@ -162,8 +157,8 @@ public class DataFiles extends ArrayList
for (int nDataFile = 0; nDataFile < this.size(); nDataFile++)
{
DataFile contentFile = this.getByIndex(nDataFile);
result.append ("== " + contentFile.name() + "\n");
result.append ("contentFile " + nDataFile + " - " + contentFile.name() + "\n");
result.append("== " + 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.Pattern;
/**
* This class groups function to help in Calendar manipulation.
*
@ -18,7 +17,8 @@ import java.util.regex.Pattern;
*/
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 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 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;
@ -45,18 +44,17 @@ public class DateHelper
}
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);
}
/**
*
*/
static public String shortEuropeanFormat (Calendar time)
static public String europeanFormat(final Calendar time)
{
String result;
@ -66,88 +64,121 @@ public class DateHelper
}
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);
}
/**
*
*/
static public String ISOFormat (Calendar time)
{
String result;
if (time == null)
{
result = "";
}
else
{
result = String.format (ISO_DATE_FORMAT, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH));
}
//
return (result);
}
/**
*
*/
static public String americanFormat (Calendar time)
{
String result;
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)
static public boolean isAmericanFormat(final String date)
{
boolean result;
if ((isEuropeanFormat (date)) ||
(isRawFormat (date)) ||
(isISOFormat (date)) ||
(isAmericanFormat (date)))
if (date == null)
{
result = false;
}
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;
}
@ -160,103 +191,19 @@ public class DateHelper
return (result);
}
/**
*
*/
static public boolean isEuropeanFormat (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)
static public Calendar parseAmericanDate(final String date)
{
Calendar result;
Pattern pattern = Pattern.compile (ISO_DATE_PATTERN);
Matcher matcher = pattern.matcher (date);
Pattern pattern = Pattern.compile(AMERICAN_DATE_PATTERN);
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)),
Integer.parseInt (matcher.group (2)) - 1,
Integer.parseInt (matcher.group (3)));
result = new GregorianCalendar(Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(1)) - 1, Integer.parseInt(matcher.group(2)));
}
else
{
@ -264,110 +211,31 @@ 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.
*/
static public Calendar parseDate (String date)
static public Calendar parseDate(final String date)
{
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
{
@ -375,6 +243,115 @@ 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.security.MessageDigest;
/**
* This class is a helper to use MessageDigester class.
*/
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"
*/
static public String computeHash (String digestMethod, File file) throws Exception
static public String computeHash(final String digestMethod, final File file) throws Exception
{
String result;
@ -60,36 +29,36 @@ public class Digester
}
else
{
//byte[] hash = null;
// byte[] hash = null;
InputStream source = null;
try
{
MessageDigest digester = MessageDigest.getInstance (digestMethod);
source = new FileInputStream (file);
MessageDigest digester = MessageDigest.getInstance(digestMethod);
source = new FileInputStream(file);
boolean ended = false;
int bytesNumber;
byte[] buffer = new byte[100*1024];
byte[] buffer = new byte[100 * 1024];
while (!ended)
{
bytesNumber = source.read (buffer);
bytesNumber = source.read(buffer);
if (bytesNumber == -1)
{
ended = true;
}
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)
{
throw new Exception("Digest method unknown.", exception);
throw new Exception("Digest method unknown.", exception);
}
catch (java.io.FileNotFoundException exception)
{
@ -111,4 +80,33 @@ public class Digester
//
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.FileOutputStream;
/**
* Never used again. Prefer org.apache.commons.io.FileUtils class.
*/
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))
{
@ -23,37 +22,37 @@ public class FileCopier
}
else
{
FileInputStream in = new FileInputStream(source);
FileOutputStream out = new FileOutputStream(target);
try
{
byte[] buffer = new byte[BUFFER_SIZE];
boolean ended = false;
while (!ended)
{
int size = in.read(buffer);
if (size == -1)
{
ended = false;
}
else
{
out.write(buffer, 0, size);
}
}
}
finally
{
if (in != null)
{
in.close();
}
if (out != null)
{
out.close();
}
}
FileInputStream in = new FileInputStream(source);
FileOutputStream out = new FileOutputStream(target);
try
{
byte[] buffer = new byte[BUFFER_SIZE];
boolean ended = false;
while (!ended)
{
int size = in.read(buffer);
if (size == -1)
{
ended = false;
}
else
{
out.write(buffer, 0, size);
}
}
}
finally
{
if (in != null)
{
in.close();
}
if (out != null)
{
out.close();
}
}
}
}
}

View file

@ -1,13 +1,10 @@
package fr.devinsy.util;
import java.io.File;
import java.util.Iterator;
import java.util.Vector;
import java.util.regex.Pattern;
/**
*
*/
@ -20,33 +17,10 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
protected File previous;
protected boolean followLinks;
/**
*
*/
public FileIterator (File root)
{
super();
String[] pathnames;
if (root == null)
{
pathnames = null;
}
else
{
pathnames = new String[1];
pathnames[0] = root.getPath();
}
init (pathnames, null, false);
}
/**
*
*/
public FileIterator (File root, String filter, boolean followLinks)
public FileIterator(final File root)
{
super();
@ -61,14 +35,34 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
pathnames[0] = root.getPath();
}
init (pathnames, filter, followLinks);
init(pathnames, null, false);
}
/**
*
*/
public FileIterator (String pathname, String filter, boolean followLinks)
public FileIterator(final File root, final String filter, final boolean followLinks)
{
super();
String[] pathnames;
if (root == null)
{
pathnames = null;
}
else
{
pathnames = new String[1];
pathnames[0] = root.getPath();
}
init(pathnames, filter, followLinks);
}
/**
*
*/
public FileIterator(final String pathname, final String filter, final boolean followLinks)
{
super();
@ -83,63 +77,92 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
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();
init(pathnames, filter, followLinks);
}
/**
*
*
*/
protected void init (String[] pathnames, String filter, boolean followLinks)
public File currentFile()
{
setFilter(filter);
this.followLinks = followLinks;
this.previous = null;
File result;
this.currentDepth = 0;
this.add(new FileIteratorState(pathnames));
result = this.currentState().currentFile();
shift();
//
return (result);
}
/**
*
*
*/
public void reset ()
protected FileIteratorState currentState()
{
this.currentDepth = 0;
this.previous = null;
if (this.size() > 0)
FileIteratorState result;
result = this.get(this.currentDepth);
//
return (result);
}
/**
*
*/
public int directoryFinalCountdown()
{
int result;
result = 0;
while (this.hasNext())
{
this.get(0).reset();
FileIteratorState firstState = this.get(0);
this.removeAllElements();
this.add(firstState);
if (this.next().isDirectory())
{
result += 1;
}
}
shift();
//
return (result);
}
/**
*
*/
public int fileFinalCountdown()
{
int result;
result = 0;
while (this.hasNext())
{
if (!this.next().isDirectory())
{
result += 1;
}
}
//
return (result);
}
/**
*
*/
protected String filter()
{
String result;
if (pattern == null)
{
result = ".*";
@ -148,118 +171,32 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
{
result = this.pattern.toString();
}
//
return(result);
return (result);
}
/**
*
*/
public Pattern pattern()
{
Pattern result;
result = this.pattern;
//
return(result);
}
/**
*
*/
protected void setFilter(String filter)
public int finalCountdown()
{
if (filter == null)
int result;
result = 0;
while (this.next() != null)
{
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;
result += 1;
}
//
return(result);
return (result);
}
/**
*
*/
public boolean follow(File file)
public boolean follow(final File file)
{
boolean result;
@ -274,8 +211,9 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
{
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)
{
@ -283,20 +221,150 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
result = false;
}
//
return(result);
return (result);
}
/**
* Set indexes to the good next item.
*
*/
@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.
*/
public void shift()
{
boolean ended = false;
while(!ended)
while (!ended)
{
File next = this.currentFile();
@ -328,132 +396,39 @@ public class FileIterator extends Vector<FileIteratorState> implements Iterator<
}
}
}
}
}
/**
*
*/
@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()
{
String result;
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.util.Iterator;
/**
* Used by FileIterator class.
*/
@ -12,27 +11,10 @@ public class FileIteratorState implements Iterator<File>
protected File[] files;
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.
this.currentIndex = 0;
@ -47,51 +29,28 @@ 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;
}
/**
*
*/
protected File[] files()
{
File[] result;
result = this.files;
//
return(result);
}
// Initialize the state.
this.currentIndex = 0;
/**
*
*/
protected int currentIndex()
{
int result;
result = this.currentIndex;
//
return(result);
this.files = new File[pathnames.length];
for (int pathnameIndex = 0; pathnameIndex < pathnames.length; pathnameIndex++)
{
this.files[pathnameIndex] = new File(pathnames[pathnameIndex]);
}
}
/**
*
*/
protected File currentFile()
{
File result;
if (this.currentIndex >= this.files.length)
{
result = null;
@ -100,12 +59,37 @@ public class FileIteratorState implements Iterator<File>
{
result = this.files[this.currentIndex];
}
//
return(result);
return (result);
}
/**
*
*/
protected int currentIndex()
{
int result;
result = this.currentIndex;
//
return (result);
}
/**
*
*/
protected File[] files()
{
File[] result;
result = this.files;
//
return (result);
}
/**
*
*/
@ -113,8 +97,7 @@ public class FileIteratorState implements Iterator<File>
public boolean hasNext()
{
boolean result;
if (this.currentFile() == null)
{
result = false;
@ -123,12 +106,11 @@ public class FileIteratorState implements Iterator<File>
{
result = true;
}
//
return(result);
return (result);
}
/**
*
*/
@ -136,20 +118,27 @@ public class FileIteratorState implements Iterator<File>
public File next()
{
File result;
result = this.currentFile();
this.currentIndex += 1;
//
return(result);
return (result);
}
/**
*
*/
@Override
public void remove()
public void remove()
{
}
}
/**
*
*/
public void reset()
{
currentIndex = 0;
}
}

View file

@ -7,40 +7,23 @@
*/
package fr.devinsy.util;
/**
*
* */
public class Fraction
public class Fraction
{
protected long numerator;
protected long denominator;
/**
*
*/
public Fraction(long numerator, long denominator)
public Fraction(final long numerator, final long denominator)
{
this.numerator = numerator;
this.denominator = denominator;
}
/**
*
*/
public long numerator()
{
long result;
result = this.numerator;
//
return (result);
}
/**
*
*/
@ -57,7 +40,20 @@ public class Fraction
/**
*
*/
public long percentage() throws Exception
public long numerator()
{
long result;
result = this.numerator;
//
return (result);
}
/**
*
*/
public long percentage() throws Exception
{
long result;
@ -67,11 +63,50 @@ public class Fraction
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;
@ -88,18 +123,30 @@ public class Fraction
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;
try
{
long value = percentage(numerator, denominator);
if (numerator == 0)
{
result = "0%";
@ -121,66 +168,8 @@ public class Fraction
{
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,11 +5,10 @@
*/
package fr.devinsy.util;
/**
*
*/
public class InternetProxyConfiguration
public class InternetProxyConfiguration
{
//
protected String host;
@ -20,19 +19,18 @@ public class InternetProxyConfiguration
/**
*
*/
public InternetProxyConfiguration ()
public InternetProxyConfiguration()
{
this.host = "";
this.port = 0;
this.login = "";
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)
@ -43,7 +41,46 @@ public class InternetProxyConfiguration
{
this.host = host;
}
//
this.port = port;
//
if (login == null)
{
this.login = "";
}
else
{
this.login = login;
}
//
if (password == null)
{
this.password = "";
}
else
{
this.password = password;
}
}
/**
*
*/
public InternetProxyConfiguration(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))
{
@ -53,15 +90,15 @@ public class InternetProxyConfiguration
{
try
{
this.port = Integer.parseInt (port);
this.port = Integer.parseInt(port);
}
catch (Exception exception)
{
String errorMessage = "Incorrect PROXY port value.";
throw new Exception (errorMessage, exception);
throw new Exception(errorMessage, exception);
}
}
//
if (login == null)
{
@ -71,7 +108,7 @@ public class InternetProxyConfiguration
{
this.login = login;
}
//
if (password == null)
{
@ -81,48 +118,7 @@ public class InternetProxyConfiguration
{
this.password = password;
}
}
/**
*
*/
public InternetProxyConfiguration (String host, int port, String login, String password)
{
//
if (host == null)
{
this.host = "";
}
else
{
this.host = host;
}
//
this.port = port;
//
if (login == null)
{
this.login = "";
}
else
{
this.login = login;
}
//
if (password == null)
{
this.password = "";
}
else
{
this.password = password;
}
}
}
/**
*
@ -130,63 +126,20 @@ public class InternetProxyConfiguration
public String host()
{
String result;
result = this.host;
//
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);
}
/**
*
*/
public boolean isInitialized()
{
boolean result;
if ((this.host.length() > 0) && (this.port > 0))
{
result = true;
@ -195,19 +148,58 @@ public class InternetProxyConfiguration
{
result = false;
}
//
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()
{
String result;
String login;
if (this.login.length() == 0)
{
@ -217,7 +209,7 @@ public class InternetProxyConfiguration
{
login = "********";
}
String password;
if (this.password.length() == 0)
{
@ -227,10 +219,10 @@ public class InternetProxyConfiguration
{
password = "********";
}
result = "(" + this.host + "," + this.port + "," + login + "," + password + ")";
//
return (result);
}
}
}

View file

@ -6,34 +6,48 @@
package fr.devinsy.util;
/**
* This class defines a simple average manager. For example, it is useful for millisecond.
* The maximum value available in input is one day in millisecond.
* This class defines a simple average manager. For example, it is useful for
* millisecond. The maximum value available in input is one day in millisecond.
*/
public class SimpleAveragemeter
{
//
protected long sum;
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();
}
/**
*
*/
synchronized public void reset()
synchronized public void add(final long value)
{
this.sum = 0;
this.cardinal = 0;
}
// Manage the sum limit.
if ((this.sum > Long.MAX_VALUE / 2) && (cardinal % 2 == 0))
{
this.sum = this.sum / 2;
this.cardinal = this.cardinal / 2;
}
// Add the new value.
if (this.sum > MAX_ADD)
{
this.sum += MAX_ADD;
this.cardinal += 1;
}
else
{
this.sum += value;
this.cardinal += 1;
}
}
/**
*
@ -48,28 +62,13 @@ public class SimpleAveragemeter
}
else
{
result = (long) sum/cardinal;
result = sum / cardinal;
}
//
return(result);
return (result);
}
/**
*
*/
public long value()
{
long result;
result = this.average();
//
return(result);
}
/**
*
*/
@ -78,47 +77,43 @@ public class SimpleAveragemeter
long result;
result = this.cardinal;
//
return(result);
return (result);
}
/**
*
*/
synchronized public void add(long value)
synchronized public void reset()
{
// Manage the sum limit.
if ((this.sum > Long.MAX_VALUE/2) && (cardinal%2 == 0))
{
this.sum = (long) this.sum /2;
this.cardinal = this.cardinal/2;
}
// Add the new value.
if (this.sum > MAX_ADD)
{
this.sum += MAX_ADD;
this.cardinal += 1;
}
else
{
this.sum += value;
this.cardinal += 1;
}
this.sum = 0;
this.cardinal = 0;
}
/**
*
*/
@Override
public String toString()
{
String result;
result = Long.toString(this.average());
//
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;
/**
*
*/
@ -16,25 +15,14 @@ public class SimpleChronometer
//
protected long firstTime;
/**
*
*/
public SimpleChronometer ()
public SimpleChronometer()
{
this.reset();
}
/**
*
*/
public void reset()
{
this.firstTime = new Date().getTime();
}
/**
*
*/
@ -45,84 +33,21 @@ public class SimpleChronometer
result = new Date().getTime() - this.firstTime;
//
return(result);
return (result);
}
/**
*
*/
static public String shortHumanString(long interval)
public void reset()
{
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);
this.firstTime = new Date().getTime();
}
/**
* TO BE COMPLETED.
*/
static public String humanString(long interval)
static public String humanString(final long interval)
{
String result;
@ -130,28 +55,97 @@ public class SimpleChronometer
{
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

@ -8,18 +8,18 @@ import java.io.PrintStream;
*/
public class StacktraceWriter
{
/**
/**
*
*/
static public String toString(Exception exception)
{
String result;
ByteArrayOutputStream out = new ByteArrayOutputStream(50000);
exception.printStackTrace(new PrintStream(out));
result = out.toString();
//
return (result);
}
static public String toString(final Exception exception)
{
String result;
ByteArrayOutputStream out = new ByteArrayOutputStream(50000);
exception.printStackTrace(new PrintStream(out));
result = out.toString();
//
return (result);
}
}

View file

@ -9,9 +9,9 @@ import java.io.IOException;
import java.util.ArrayList;
/**
* This class is a collection of String objects with specific methods.
* It makes possible to build a string without any copy.
* The goal is to optimize the building of strings where they are lot of concatenation action.
* This class is a collection of String objects with specific methods. It makes
* possible to build a string without any copy. The goal is to optimize the
* building of strings where they are lot of concatenation action.
*/
public class StringConcatenator extends ArrayList<String>
{
@ -21,46 +21,30 @@ public class StringConcatenator extends ArrayList<String>
/**
*
*/
public StringConcatenator ()
public StringConcatenator()
{
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);
}
/**
*
*/
public StringConcatenator appendln()
{
StringConcatenator result;
this.add(LINE_SEPARATOR);
result = this;
//
return(result);
}
/**
*
*/
public StringConcatenator append(String string)
public StringConcatenator append(final String string)
{
StringConcatenator result;
@ -72,58 +56,13 @@ public class StringConcatenator extends ArrayList<String>
result = this;
//
return(result);
return (result);
}
/**
*
*/
public StringConcatenator appendln(String 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)
public StringConcatenator append(final StringConcatenator string)
{
StringConcatenator result;
@ -138,33 +77,75 @@ public class StringConcatenator extends ArrayList<String>
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;
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++)
{
out.write(this.getByIndex(nString));
}
StringConcatenator result;
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()
{
String result;
@ -201,17 +182,27 @@ public class StringConcatenator extends ArrayList<String>
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;
if (strings == null)
{
result = null;
@ -219,51 +210,49 @@ public class StringConcatenator extends ArrayList<String>
else
{
StringConcatenator string = new StringConcatenator();
for (int nString = 0; nString < strings.length; nString++)
{
string.append(strings[nString]);
if (nString < strings.length - 1)
{
string.append(' ');
}
}
result = string.toString();
}
//
return(result);
}
//
return (result);
}
/**
*
*/
static public String toStringNotNull(String[] strings)
static public String toStringNotNull(final String[] strings)
{
String result;
result = toString(strings);
if (result == null)
{
result = "";
}
//
return(result);
return (result);
}
/**
*
*/
static public String toStringWithBracket(String[] strings)
static public String toStringWithBracket(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
@ -271,26 +260,43 @@ public class StringConcatenator extends ArrayList<String>
else
{
StringConcatenator merge = new StringConcatenator();
merge.append("[");
merge.append(toStringWithCommas(strings));
merge.append("]");
result = merge.toString();
}
//
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;
@ -298,32 +304,58 @@ public class StringConcatenator extends ArrayList<String>
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;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(",");
}
merge.append(string);
}
result = merge.toString();
}
//
return(result);
return (result);
}
/**
*
*/
static public String toStringWithFrenchCommas(String[] strings)
static public String toStringWithFrenchCommas(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
@ -331,68 +363,21 @@ public class StringConcatenator extends ArrayList<String>
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(", ");
}
merge.append(string);
}
result = merge.toString();
}
//
return(result);
}
/**
*
*/
static public String toStringWithBrackets(String[] strings)
{
String result;
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);
return (result);
}
}

View file

@ -9,9 +9,9 @@ import java.io.IOException;
import java.util.ArrayList;
/**
* This class is a collection of String objects with specific methods.
* It makes possible to build a string without any copy.
* The goal is to optimize the building of strings where they are lot of concatenation action.
* This class is a collection of String objects with specific methods. It makes
* possible to build a string without any copy. The goal is to optimize the
* building of strings where they are lot of concatenation action.
*/
public class StringList extends ArrayList<String>
{
@ -21,55 +21,64 @@ public class StringList extends ArrayList<String>
/**
*
*/
public StringList ()
public StringList()
{
super();
}
/**
*
*/
public StringList (int size)
public StringList(final int 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);
}
/**
*
*/
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;
this.add(LINE_SEPARATOR);
result = this;
result = this.append(String.valueOf(value));
//
return(result);
return (result);
}
/**
* Check null parameter before add.
*/
public StringList append(String string)
public StringList append(final String string)
{
StringList result;
@ -81,14 +90,13 @@ public class StringList extends ArrayList<String>
result = this;
//
return(result);
return (result);
}
/**
*
*/
public StringList append(String ... strings)
public StringList append(final String... strings)
{
StringList result;
@ -103,128 +111,13 @@ public class StringList extends ArrayList<String>
result = this;
//
return(result);
return (result);
}
/**
*
*/
public StringList appendln(String 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)
public StringList append(final StringList string)
{
StringList result;
@ -239,33 +132,114 @@ public class StringList extends ArrayList<String>
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;
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++)
{
out.write(this.getByIndex(nString));
}
StringList result;
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,13 +255,31 @@ public class StringList extends ArrayList<String>
}
//
return(result);
return (result);
}
/**
*
*/
public StringList removeLast()
{
StringList result;
if (this.size() > 0)
{
this.remove(this.size() - 1);
}
result = this;
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
@ -302,56 +294,46 @@ public class StringList extends ArrayList<String>
result = new String(preResult);
//
return(result);
return (result);
}
/**
*
*/
public StringList removeLast()
{
StringList result;
if (this.size() > 0)
{
this.remove(this.size() - 1);
}
result = this;
//
return(result);
}
/**
*
*/
static public String multiply(String source, int number)
public void writeInto(final java.io.Writer out) throws IOException
{
for (int nString = 0; nString < this.size(); nString++)
{
out.write(this.getByIndex(nString));
}
}
/**
*
*/
static public String multiply(final String source, final int number)
{
String result;
StringList strings = new StringList();
for (int index = 0; index < number; index++)
{
strings.append(source);
}
result = strings.toString();
//
return(result);
return (result);
}
/**
*
*/
static public String toString(String[] strings)
static public String toString(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
@ -359,51 +341,49 @@ public class StringList extends ArrayList<String>
else
{
StringConcatenator string = new StringConcatenator();
for (int nString = 0; nString < strings.length; nString++)
{
string.append(strings[nString]);
if (nString < strings.length - 1)
{
string.append(' ');
}
}
result = string.toString();
}
//
return(result);
}
//
return (result);
}
/**
*
*/
static public String toStringNotNull(String[] strings)
static public String toStringNotNull(final String[] strings)
{
String result;
result = toString(strings);
if (result == null)
{
result = "";
}
//
return(result);
return (result);
}
/**
*
*/
static public String toStringWithBracket(String[] strings)
static public String toStringWithBracket(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
@ -411,26 +391,43 @@ public class StringList extends ArrayList<String>
else
{
StringConcatenator merge = new StringConcatenator();
merge.append("[");
merge.append(toStringWithCommas(strings));
merge.append("]");
result = merge.toString();
}
//
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;
@ -438,32 +435,58 @@ public class StringList extends ArrayList<String>
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;
if (strings == null)
{
result = null;
}
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(",");
}
merge.append(string);
}
result = merge.toString();
}
//
return(result);
return (result);
}
/**
*
*/
static public String toStringWithFrenchCommas(String[] strings)
static public String toStringWithFrenchCommas(final String[] strings)
{
String result;
if (strings == null)
{
result = null;
@ -471,68 +494,21 @@ public class StringList extends ArrayList<String>
else
{
StringConcatenator merge = new StringConcatenator();
for (String string : strings)
{
if (merge.size() != 0)
{
merge.append(", ");
}
merge.append(string);
}
result = merge.toString();
}
//
return(result);
}
/**
*
*/
static public String toStringWithBrackets(String[] strings)
{
String result;
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);
return (result);
}
}

View file

@ -8,15 +8,13 @@ package fr.devinsy.util;
import java.io.IOException;
import java.io.Writer;
/**
*
*/
public class StringListWriter extends Writer
{
protected StringList out;
/**
*
*/
@ -24,58 +22,55 @@ public class StringListWriter extends Writer
{
this.out = new StringList();
}
/**
*
*/
StringListWriter(int size)
StringListWriter(final int size)
{
this.out = new StringList(size);
}
/*
*
*/
@Override
public void close() throws IOException
{
}
/*
*
*/
@Override
public void flush() throws IOException
public void flush() throws IOException
{
}
/*
*
*/
@Override
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
public void write(final char c) throws IOException
{
this.out.append(c);
}
/*
*
*/
public void write(String string) throws IOException
@Override
public void write(final char[] cbuf, final int off, final int len) throws IOException
{
this.out.append(cbuf.toString().substring(off, len));
}
/*
*
*/
@Override
public void write(final String string) throws IOException
{
this.out.append(string);
}

View file

@ -2,19 +2,17 @@ package fr.devinsy.util.cmdexec;
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
{
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 String out;
protected String err;
// ////////////////////////////////////////////////////////////////////
//
@ -23,56 +21,50 @@ 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)
{
run (command, StreamGobbler.NONE, StreamGobbler.NONE);
}
/**
*
*/
public CmdExec (String command, int STDOUT, int STDERR)
{
run (command, STDOUT, STDERR);
}
/**
*
*/
public CmdExec (String[] command, int STDOUT, int STDERR)
public CmdExec(final String... command)
{
run (command, STDOUT, STDERR);
run(command, StreamGobbler.NONE, StreamGobbler.NONE);
}
/**
*
*/
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 CmdExec(final String[] command, final int STDOUT, final int STDERR)
{
run(command, STDOUT, STDERR);
}
/**
*
*/
public CmdExec(final String[] command, final StreamGobbler outputGobbler, final StreamGobbler errorGobbler)
{
run(command, outputGobbler, errorGobbler);
}
// ////////////////////////////////////////////////////////////////////
//
@ -80,342 +72,146 @@ public class CmdExec
/**
*
* @return
*/
public int run (String command, int STDOUT, int STDERR)
public String getErrStream()
{
int result;
result = run (command,
new StreamGobbler ("OUTPUT", STDOUT),
new StreamGobbler ("ERROR", STDERR));
String result;
result = this.err;
//
return (result);
}
//
public int run (String[] command, int STDOUT, int STDERR)
/**
*
* @return
*/
public int getExitValue()
{
int result;
result = run (command,
new StreamGobbler ("OUTPUT", STDOUT),
new StreamGobbler ("ERROR", STDERR));
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 (String[] command, StreamGobbler outputGobbler, StreamGobbler errorGobbler)
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) + "]");
logger.info("CmdExec(commande[]) = [" + StringConcatenator.toString(command) + "]");
logger.info("CmdExec(commande[]) = [" + StringConcatenator.toStringWithBrackets(command) + "]");
try
{
Runtime rt = Runtime.getRuntime ();
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);
// Any error message?
errorGobbler.setInputStream (proc.getErrorStream ());
errorGobbler.setInputStream(proc.getErrorStream());
// Any output?
outputGobbler.setInputStream (proc.getInputStream ());
outputGobbler.setInputStream(proc.getInputStream());
// Kick them off
errorGobbler.start ();
outputGobbler.start ();
errorGobbler.start();
outputGobbler.start();
// Any error???
this.exitValue = proc.waitFor ();
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 ()))
// Sometimes, process ends before Gobblers read its outpout, so we
// must wait them.
while ((!outputGobbler.isOver()) || (!errorGobbler.isOver()))
{
Thread.sleep (2);
Thread.sleep(2);
}
out = outputGobbler.getStream ();
err = errorGobbler.getStream ();
out = outputGobbler.getStream();
err = errorGobbler.getStream();
}
catch (Exception exception)
{
this.err = exception.getMessage();
this.exitValue = -77;
exception.printStackTrace ();
exception.printStackTrace();
}
//
return (this.exitValue);
}
/**
*
* @param command: not a shell command, it must be a executable program.
* @param outputGobbler
* @param errorGobbler
* @return
*/
public int run (String command, StreamGobbler outputGobbler, StreamGobbler errorGobbler)
{
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;
result = this.err;
//
return (result);
}
// ////////////////////////////////////////////////////////////////////
//
// ////////////////////////////////////////////////////////////////////
/**
*
*/
static public String run (String command) throws Exception
{
String result;
result = CmdExec.run(command.split("[ \t\n\r\f]"));
//
return(result);
}
/**
*
*/
static public String run (String ... command) throws Exception
{
String result;
if ((command == null) || (command.length == 0))
{
throw new Exception("Empty command");
}
else
{
CmdExec cmd = new CmdExec (command,
StreamGobbler.BUFFER,
StreamGobbler.BUFFER);
if (cmd.getExitValue() == 0)
{
result = cmd.getOutStream();
}
else
{
logger.error("Command=\"" + StringConcatenator.toStringWithBrackets(command));
logger.error("Command=\"[" + StringConcatenator.toString(command) + "]\n out => [" + cmd.getOutStream() + "]\n " + "err => (" + cmd.getErrStream().length () +")[" + cmd.getErrStream() + "]");
throw new Exception(cmd.getErrStream());
}
}
//
return (result);
}
/**
* Examples:
* 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");
*/
static public String run (String program1, String program2, 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 (program1 == null)
{
throw new Exception ("Null program parameter 1 detected: [" + program1 + "].");
}
else if (program2 == null)
{
throw new Exception ("Null program parameter 2 detected: [" + program2 + "].");
}
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 + 2];
command[0] = program1;
command[1] = program2;
for (nArg = 0; nArg < args.length; nArg++)
{
command[nArg + 2] = args[nArg];
}
result = CmdExec.run (command);
}
//
return(result);
}
/**
*
*/
static public String multirun (String ... commands) throws Exception
static public String multirun(final String... commands) throws Exception
{
String result;
@ -429,14 +225,14 @@ public class CmdExec
{
String command = commands[commandCounter];
if ((command == null) || (command.length () == 0))
if ((command == null) || (command.length() == 0))
{
result = null;
commandCounter += 1;
}
else
{
result += CmdExec.run (command);
result += CmdExec.run(command);
commandCounter += 1;
}
}
@ -450,4 +246,183 @@ public class CmdExec
//
return (result);
}
// ////////////////////////////////////////////////////////////////////
//
// ////////////////////////////////////////////////////////////////////
/**
*
*/
static public String run(final String command) throws Exception
{
String result;
result = CmdExec.run(command.split("[ \t\n\r\f]"));
//
return (result);
}
/**
*
*/
static public String run(final String... command) throws Exception
{
String result;
if ((command == null) || (command.length == 0))
{
throw new Exception("Empty command");
}
else
{
CmdExec cmd = new CmdExec(command, StreamGobbler.BUFFER, StreamGobbler.BUFFER);
if (cmd.getExitValue() == 0)
{
result = cmd.getOutStream();
}
else
{
logger.error("Command=\"" + StringConcatenator.toStringWithBrackets(command));
logger.error("Command=\"[" + StringConcatenator.toString(command) + "]\n out => [" + cmd.getOutStream() + "]\n " + "err => (" + cmd.getErrStream().length() + ")["
+ cmd.getErrStream() + "]");
throw new Exception(cmd.getErrStream());
}
}
//
return (result);
}
/**
* Examples: setfacl("sudo", "setfacl", "-m", "g:cpm:rwX", "/tmp/toto");
* setfacl("sudo", "setfacl", "-R", "-m", "g:cpm:rwX", "/tmp/toto");
*/
static public String run(final String program1, final String program2, final String[] args, final int min, final 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 (program1 == null)
{
throw new Exception("Null program parameter 1 detected: [" + program1 + "].");
}
else if (program2 == null)
{
throw new Exception("Null program parameter 2 detected: [" + program2 + "].");
}
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 + 2];
command[0] = program1;
command[1] = program2;
for (nArg = 0; nArg < args.length; nArg++)
{
command[nArg + 2] = args[nArg];
}
result = CmdExec.run(command);
}
//
return (result);
}
/**
* Examples: setfacl("setfacl", "-m", "g:cpm:rwX", "/tmp/toto");
* setfacl("setfacl", "-R", "-m", "g:cpm:rwX", "/tmp/toto");
*/
static public String run(final String program, final String[] args, final int min, final 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);
}
}

View file

@ -5,14 +5,13 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
*
*/
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 PRINT = 1;
static final public int BUFFER = 2;
@ -21,129 +20,75 @@ public class StreamGobbler extends Thread
protected String type;
protected int streamWay;
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.streamWay = NONE;
this.stream = new StringBuffer ();
this.stream = new StringBuffer();
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 type
*/
StreamGobbler (InputStream is, String type)
StreamGobbler(final InputStream is, final String type)
{
this.is = is;
this.type = type;
this.streamWay = NONE;
this.stream = new StringBuffer ();
this.stream = new StringBuffer();
this.isOverStatus = false;
}
/**
*
* @param is
* @param type
* @param streamWay
*/
StreamGobbler (InputStream is, String type, int streamWay)
StreamGobbler(final InputStream is, final String type, final int streamWay)
{
this.is = is;
this.type = type;
this.streamWay = streamWay;
this.stream = new StringBuffer ();
this.stream = new StringBuffer();
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
*/
public String getStream ()
public String getStream()
{
String result;
if (this.stream != null)
{
result = this.stream.toString ();
result = this.stream.toString();
}
else
{
@ -154,18 +99,71 @@ public class StreamGobbler extends Thread
return (result);
}
/**
*
* @return
*/
public boolean isOver ()
public boolean isOver()
{
boolean result;
result = this.isOverStatus;
//
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.PrintWriter;
/**
*
*/
public class Wrapper
{
static private final Wrapper instance = new Wrapper ();
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (Wrapper.class);
static private final Wrapper instance = new Wrapper();
static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Wrapper.class);
/**
/**
* return instance of the controller
*/
public static Wrapper instance ()
public static Wrapper instance()
{
return (instance);
}
/**
*
*/
static public void wrap (String ressource, PrintWriter output) throws IOException
static public StringBuffer wrap(final String ressource) throws IOException
{
logger.info ("Enter");
BufferedReader buf = new BufferedReader (new FileReader (ressource));
String ligne;
while ((ligne = buf.readLine()) != null)
{
output.print (ligne);
}
logger.info ("Exit");
}
/**
*
*/
static public StringBuffer wrap (String ressource) throws IOException
{
logger.info ("Enter");
logger.info("Enter");
StringBuffer result;
result = new StringBuffer ();
result = new StringBuffer();
BufferedReader buf = new BufferedReader (new FileReader (ressource));
BufferedReader buf = new BufferedReader(new FileReader(ressource));
String ligne;
while ((ligne = buf.readLine()) != null)
{
result.append (ligne + "\n");
result.append(ligne + "\n");
}
//
logger.info ("Exit");
logger.info("Exit");
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;
import java.io.*;
import java.io.File;
/**
*
*/
public class CachedFile
{
static private org.apache.log4j.Logger logger;
static
{
logger = org.apache.log4j.Logger.getLogger (CachedFile.class);
public enum Status
{
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 long sourceTime;
@ -24,18 +21,17 @@ public class CachedFile
/**
*
*/
public CachedFile (String fileName)
public CachedFile(final String fileName)
{
this.sourceName = fileName;
this.sourceTime = 0;
this.status = Status.NOT_LOAD;
}
/**
*
*/
protected File getSourceFile ()
protected File getSourceFile()
{
File result;
@ -45,11 +41,11 @@ public class CachedFile
}
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;
}
else
@ -62,21 +58,20 @@ public class CachedFile
return (result);
}
/**
*
*/
protected Status getStatus ()
protected Status getStatus()
{
Status result;
File source = getSourceFile ();
File source = getSourceFile();
if (source == null)
{
this.status = Status.NOT_LOAD;
}
else if (this.sourceTime != source.lastModified ())
else if (this.sourceTime != source.lastModified())
{
this.status = Status.EXPIRED;
}
@ -87,13 +82,20 @@ public class CachedFile
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)
{
@ -101,19 +103,10 @@ public class CachedFile
}
else
{
this.sourceTime = source.lastModified ();
this.sourceTime = source.lastModified();
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;
/**
*
*/
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;
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;
}
/**
/*
*
*/
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);
}
/**
*
*/
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)
{
Group result;
Groups groups = updatedGroups();
if (groups == null)
{
result = null;
}
else
{
result = groups.getByName(name);
}
//
return (result);
}
/**
*
*/
public Vector<String> getLoginGroups(final String login)
{
Vector<String> result;
Groups groups = updatedGroups();
result = groups.getLoginGroups(login);
//
return (result);
}
/**
*
*/
public String getLoginGroupsString(final String login)
{
String result;
groups = updatedGroups();
result = groups.getLoginGroupsString(login);
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = this.groups.toString();
//
return (result);
}
/**
*
*/
protected Groups updatedGroups()
{
Groups result;
if (getStatus () != Status.UPDATED)
if (getStatus() != Status.UPDATED)
{
this.groups = EtcGroupFileReader.load ();
this.groups = EtcGroupFileReader.load();
if (this.groups == null)
{
setNotLoad ();
setNotLoad();
}
else
{
setUpdated ();
setUpdated();
}
}
@ -69,116 +159,19 @@ public class EtcGroupFile extends CachedFile
return (result);
}
/**
*
*/
public Group get (String name)
static public EtcGroupFile instance()
{
Group result;
EtcGroupFile result;
Groups groups = updatedGroups ();
if (groups == null)
if (EtcGroupFile.instance == null)
{
result = null;
}
else
{
result = groups.getByName (name);
EtcGroupFile.instance = new EtcGroupFile();
}
//
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 ();
result = EtcGroupFile.instance;
//
return (result);

View file

@ -4,19 +4,17 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
/**
*
*/
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;
@ -24,11 +22,11 @@ public class EtcGroupFileReader
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;
}
@ -38,44 +36,44 @@ public class EtcGroupFileReader
}
else
{
result = new Groups ();
result = new Groups();
try
{
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.setName (tokens[0]);
group.setPassword (tokens[1]);
group.setGid ((new Integer (tokens[2])).intValue ());
Group group = new Group();
group.setName(tokens[0]);
group.setPassword(tokens[1]);
group.setGid((new Integer(tokens[2])).intValue());
// Manage the case of empty shell.
if (tokens.length == 4)
{
String[] tokensBis = tokens[3].split (",");
String[] tokensBis = tokens[3].split(",");
for (int tokenCounter = 0; tokenCounter < tokensBis.length; tokenCounter++)
{
group.addMember (tokensBis[tokenCounter]);
group.addMember(tokensBis[tokenCounter]);
}
}
result.add (group);
result.add(group);
}
file.close();
}
catch (java.io.IOException exception)
{
logger.error ("Exception here.");
logger.error("Exception here.");
result = null;
}
}
//
return (result);
return (result);
}
}

View file

@ -1,146 +1,32 @@
package fr.devinsy.util.unix;
/**
*
*/
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;
protected Users users;
/**
*
*/
protected EtcPasswdFile ()
protected EtcPasswdFile()
{
super ("/etc/passwd");
super("/etc/passwd");
this.users = null;
}
/**
*
*/
static public EtcPasswdFile instance ()
{
EtcPasswdFile result;
if (EtcPasswdFile.instance == null)
{
EtcPasswdFile.instance = new EtcPasswdFile ();
}
result = EtcPasswdFile.instance;
//
return (result);
}
/**
*
*/
protected Users update ()
{
Users result;
logger.debug ("updating");
this.users = EtcPasswdFileReader.load ();
if (this.users == null)
{
setNotLoad ();
}
else
{
setUpdated ();
}
result = this.users;
//
return (result);
}
/**
*
*/
protected Users updatedUsers ()
{
Users result;
if (getStatus () != Status.UPDATED)
{
update();
}
result = this.users;
//
return (result);
}
/**
*
*/
public User get (String login)
{
User result;
Users users = updatedUsers ();
if (users == null)
{
result = null;
}
else
{
result = users.getByLogin (login);
}
//
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)
public boolean contains(final String login)
{
boolean result;
Users users = updatedUsers ();
Users users = updatedUsers();
if (users == null)
{
@ -148,22 +34,127 @@ public class EtcPasswdFile extends CachedFile
}
else
{
result = users.contains (login);
result = users.contains(login);
}
//
return (result);
}
/**
*
*/
public User get(final int uid)
{
User result;
Users users = updatedUsers();
if (users == null)
{
result = null;
}
else
{
result = users.getByUid(uid);
}
//
return (result);
}
/**
*
*/
public String toString ()
public User get(final String login)
{
User result;
Users users = updatedUsers();
if (users == null)
{
result = null;
}
else
{
result = users.getByLogin(login);
}
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
result = this.users.toString ();
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;
//
return (result);
}
/**
*
*/
protected Users updatedUsers()
{
Users result;
if (getStatus() != Status.UPDATED)
{
update();
}
result = this.users;
//
return (result);
}
/**
*
*/
static public EtcPasswdFile instance()
{
EtcPasswdFile result;
if (EtcPasswdFile.instance == null)
{
EtcPasswdFile.instance = new EtcPasswdFile();
}
result = EtcPasswdFile.instance;
//
return (result);

View file

@ -4,19 +4,17 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
/**
*
*/
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;
@ -24,11 +22,11 @@ public class EtcPasswdFileReader
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;
}
@ -38,47 +36,47 @@ public class EtcPasswdFileReader
}
else
{
result = new Users ();
result = new Users();
try
{
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.setLogin (tokens[0]);
user.setPassword (tokens[1]);
user.setUid ((new Integer (tokens[2])).intValue ());
user.setGid ((new Integer (tokens[3])).intValue ());
user.setRealName (tokens[4]);
user.setHomeDirectory (tokens[5]);
User user = new User();
user.setLogin(tokens[0]);
user.setPassword(tokens[1]);
user.setUid((new Integer(tokens[2])).intValue());
user.setGid((new Integer(tokens[3])).intValue());
user.setRealName(tokens[4]);
user.setHomeDirectory(tokens[5]);
// Manage the case of empty shell.
if (tokens.length == 7)
{
user.setShell (tokens[6]);
user.setShell(tokens[6]);
}
else
{
user.setShell ("");
user.setShell("");
}
result.add (user);
result.add(user);
}
file.close();
}
catch (java.io.IOException exception)
{
logger.error ("Exception here.");
logger.error("Exception here.");
result = null;
}
}
//
return (result);
return (result);
}
}

View file

@ -2,14 +2,13 @@ package fr.devinsy.util.unix;
import java.util.Vector;
/**
*
*/
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
@ -24,41 +23,37 @@ public class Group
* };
*/
protected String name;
protected String password;
protected int gid;
protected Vector<String> members;
/**
*
*/
public Group ()
public Group()
{
this.name = null;
this.password = null;
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;
@ -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;
@ -84,7 +118,7 @@ public class Group
/**
*
*/
public Vector<String> getMembers ()
public Vector<String> members()
{
Vector<String> result;
@ -94,25 +128,10 @@ public class Group
return (result);
}
/**
*
*/
public Vector<String> members ()
{
Vector<String> result;
result = this.members;
//
return (result);
}
/**
*
*/
public String getName ()
public String name()
{
String result;
@ -125,20 +144,7 @@ public class Group
/**
*
*/
public String name ()
{
String result;
result = this.name;
//
return (result);
}
/**
*
*/
public String passwd ()
public String passwd()
{
String result;
@ -151,20 +157,7 @@ public class Group
/**
*
*/
public String getPassword ()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public void setGid (int gid)
public void setGid(final int 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;
}
@ -180,7 +173,7 @@ public class Group
/**
*
*/
public void setPasswd (String password)
public void setPasswd(final String 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;
}
@ -196,7 +189,8 @@ public class Group
/**
*
*/
public String toString ()
@Override
public String toString()
{
String result;

View file

@ -3,7 +3,6 @@ package fr.devinsy.util.unix;
import java.util.Iterator;
import java.util.Vector;
/**
*
*/
@ -11,22 +10,94 @@ public class Groups extends Vector<Group>
{
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;
@ -38,13 +109,13 @@ public class Groups extends Vector<Group>
{
result = null;
boolean ended = false;
Iterator<Group> iterator = this.iterator ();
Iterator<Group> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext ())
if (iterator.hasNext())
{
Group group = iterator.next ();
if (group.getName ().equals (name))
Group group = iterator.next();
if (group.getName().equals(name))
{
ended = true;
result = group;
@ -59,102 +130,26 @@ public class Groups extends Vector<Group>
}
//
return (result);
return (result);
}
/**
*
*/
public Group getByGid (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 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)
public Vector<String> getLoginGroups(final String login)
{
Vector<String> result;
result = new Vector<String> ();
Iterator<Group> iterator = this.iterator ();
result = new Vector<String>();
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);
}
/**
*
*/
public String getLoginGroupsString (String login)
public String getLoginGroupsString(final String login)
{
String result;
Vector<String> groups = getLoginGroups (login);
Vector<String> groups = getLoginGroups(login);
StringBuffer string = new StringBuffer ();
StringBuffer string = new StringBuffer();
for (String group : groups)
{
if (string.length () == 0)
if (string.length() == 0)
{
string.append (group);
string.append(group);
}
else
{
string.append (",");
string.append (group);
string.append(",");
string.append(group);
}
}
result = string.toString ();
result = string.toString();
//
return (result);
}
/**
*
*/
public String toString ()
@Override
public String toString()
{
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);

View file

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

View file

@ -1,12 +1,12 @@
package fr.devinsy.util.unix;
/**
*
*/
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
@ -32,11 +32,10 @@ public class User
protected String homeDirectory;
protected String shell;
/**
*
*/
public User ()
public User()
{
this.login = null;
this.password = null;
@ -47,11 +46,10 @@ public class User
this.shell = null;
}
/**
*
*/
public User (User user)
public User(final User user)
{
this.login = user.login();
this.password = user.passwd();
@ -62,11 +60,10 @@ public class User
this.shell = user.shell();
}
/**
*
*/
public int getGid ()
public int getGid()
{
int result;
@ -76,39 +73,10 @@ public class User
return (result);
}
/**
*
*/
public int gid ()
{
int result;
result = this.gid;
//
return (result);
}
/**
*
*/
public String getHomeDirectory ()
{
String result;
result = this.homeDirectory;
//
return (result);
}
/**
*
*/
public String homeDirectory ()
public String getHomeDirectory()
{
String result;
@ -118,11 +86,10 @@ public class User
return (result);
}
/**
*
*/
public String getLogin ()
public String getLogin()
{
String result;
@ -132,25 +99,10 @@ public class User
return (result);
}
/**
*
*/
public String login ()
{
String result;
result = this.login;
//
return (result);
}
/**
*
*/
public String getPasswd ()
public String getPasswd()
{
String result;
@ -160,11 +112,10 @@ public class User
return (result);
}
/**
*
*/
public String passwd ()
public String getPassword()
{
String result;
@ -174,25 +125,10 @@ public class User
return (result);
}
/**
*
*/
public String getPassword ()
{
String result;
result = this.password;
//
return (result);
}
/**
*
*/
public String getRealName ()
public String getRealName()
{
String result;
@ -202,39 +138,10 @@ public class User
return (result);
}
/**
*
*/
public String realName ()
{
String result;
result = this.realName;
//
return (result);
}
/**
*
*/
public String getShell ()
{
String result;
result = this.shell;
//
return (result);
}
/**
*
*/
public String shell ()
public String getShell()
{
String result;
@ -244,11 +151,10 @@ public class User
return (result);
}
/**
*
*/
public int getUid ()
public int getUid()
{
int result;
@ -261,93 +167,150 @@ public class User
/**
*
*/
public int uid ()
public int gid()
{
int result;
result = this.uid;
result = this.gid;
//
return (result);
}
/**
*
*/
public void setHomeDirectory (String homeDirectory)
public String homeDirectory()
{
this.homeDirectory = homeDirectory;
String result;
result = this.homeDirectory;
//
return (result);
}
/**
*
*/
public void setGid (int gid)
public String login()
{
String result;
result = this.login;
//
return (result);
}
/**
*
*/
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;
}
/**
*
*/
public void setLogin (String login)
public void setHomeDirectory(final String homeDirectory)
{
this.homeDirectory = homeDirectory;
}
/**
*
*/
public void setLogin(final String login)
{
this.login = login;
}
/**
*
*/
public void setPasswd (String password)
public void setPasswd(final String password)
{
this.password = password;
}
/**
*
*/
public void setPassword (String password)
public void setPassword(final String password)
{
this.password = password;
}
/**
*
*/
public void setRealName (String realName)
public void setRealName(final String realName)
{
this.realName = realName;
}
/**
*
*/
public void setShell (String shell)
public void setShell(final String shell)
{
this.shell = shell;
}
/**
*
*/
public void setUid (int uid)
public void setUid(final int uid)
{
this.uid = uid;
}
/**
*
*/
public String toString ()
public String shell()
{
String result;
result = this.shell;
//
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
@ -356,6 +319,19 @@ public class User
//
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.Vector;
/**
*
*/
public class Users extends Vector<User>
{
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;
@ -37,13 +76,13 @@ public class Users extends Vector<User>
{
result = null;
boolean ended = false;
Iterator<User> iterator = this.iterator ();
Iterator<User> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext ())
if (iterator.hasNext())
{
User user = iterator.next ();
if (user.getLogin ().equals (login))
User user = iterator.next();
if (user.getLogin().equals(login))
{
ended = true;
result = user;
@ -58,26 +97,25 @@ public class Users extends Vector<User>
}
//
return (result);
return (result);
}
/**
*
*/
public User getByUid (int uid)
public User getByUid(final int uid)
{
User result;
result = null;
boolean ended = false;
Iterator<User> iterator = this.iterator ();
Iterator<User> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext ())
if (iterator.hasNext())
{
User user = iterator.next ();
if (user.getUid () == uid)
User user = iterator.next();
if (user.getUid() == uid)
{
ended = true;
result = user;
@ -90,71 +128,29 @@ public class Users extends Vector<User>
}
}
//
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;
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);

View file

@ -1,14 +1,13 @@
package fr.devinsy.util.unix.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
# owner: goo39
@ -36,11 +35,10 @@ public class Acl
protected AclEntries currentAcl;
protected AclEntries defaultAcl;
/**
*
*/
public Acl (String filePathname)
public Acl(final String filePathname)
{
this.filePathname = filePathname;
this.owner = "";
@ -48,131 +46,47 @@ public class Acl
this.currentAcl = new AclEntries();
this.defaultAcl = new AclEntries();
}
/**
*
*/
public String filePathname()
{
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)
public boolean contains(final AclEntry.Type type, final String id)
{
boolean result;
result = contains(AclEntry.Type.USER, login);
//
return(result);
}
if ((this.currentAcl().contains(type, id)) || (this.defaultAcl().contains(type, id)))
{
result = true;
}
else
{
result = false;
}
//
return (result);
}
/**
*
*/
public boolean containsGroup(String group)
public boolean containsGroup(final String group)
{
boolean result;
result = contains(AclEntry.Type.GROUP, group);
//
return(result);
}
//
return (result);
}
/**
*
*/
public boolean containsId(String id)
public boolean containsId(final String id)
{
boolean result;
if ((containsUser(id) || containsGroup(id)))
{
result = true;
@ -181,31 +95,103 @@ public class Acl
{
result = false;
}
//
return(result);
return (result);
}
/**
*
*/
public boolean contains(AclEntry.Type type, String id)
public boolean containsUser(final String login)
{
boolean result;
if ((this.currentAcl().contains(type, id)) ||
(this.defaultAcl().contains(type, id)))
{
result = true;
}
else
{
result = false;
}
result = contains(AclEntry.Type.USER, login);
//
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.Vector;
/**
*
*/
public class AclEntries extends Vector<AclEntry>
{
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 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 (AclEntry.Type type, String id)
public AclEntry get(final AclEntry.Type type, final String id)
{
AclEntry result;
result = null;
boolean ended = false;
Iterator<AclEntry> iterator = this.iterator ();
Iterator<AclEntry> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext ())
if (iterator.hasNext())
{
AclEntry entry = iterator.next ();
if ((type == entry.type()) && (entry.id ().equals(id)))
AclEntry entry = iterator.next();
if ((type == entry.type()) && (entry.id().equals(id)))
{
ended = true;
result = entry;
@ -50,41 +90,65 @@ 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;
}
else
{
result = true;
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 String[] getUserIds ()
public String[] getUserIds()
{
String[] result;
//
Vector<String> ids = new Vector<String> ();
Vector<String> ids = new Vector<String>();
for (AclEntry entry : this)
{
if ((entry.type == AclEntry.Type.USER) && (!ids.contains(entry.id())))
@ -95,105 +159,35 @@ public class AclEntries extends Vector<AclEntry>
//
result = new String[ids.size()];
for (int nId = 0; nId < ids.size(); nId++)
{
result[nId] = ids.get(nId);
result[nId] = ids.get(nId);
}
//
return (result);
}
/**
*
*/
public String[] getGroupIds ()
{
String[] result;
Vector<String> ids = new Vector<String> ();
for (AclEntry entry : this)
{
if ((entry.type == AclEntry.Type.GROUP) && (!ids.contains(entry.id())))
{
ids.add(entry.id());
}
}
result = (String[]) ids.toArray();
//
return (result);
}
/**
*
*/
public String[] getIds ()
{
String[] result;
Vector<String> ids = new Vector<String> ();
for (AclEntry entry : this)
{
if (!ids.contains(entry.id()))
{
ids.add(entry.id());
}
}
result = (String[]) ids.toArray();
//
return (result);
}
/**
*
*/
public boolean containsId(String id)
{
boolean result;
if ((this.get(AclEntry.Type.USER, id) == null) &&
(this.get(AclEntry.Type.GROUP, id) == null))
{
result = false;
}
else
{
result = true;
}
//
return(result);
}
/**
*
*/
public String toString ()
@Override
public String toString()
{
String result;
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);

View file

@ -1,14 +1,13 @@
package fr.devinsy.util.unix.acl;
/**
*
*/
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:cpm:rwx #effective:rwx
@ -18,53 +17,38 @@ public class AclEntry
mask::rwx
other::---
*/
public enum Type {NONE, USER, GROUP, MASK, OTHER};
public enum Type
{
NONE, USER, GROUP, MASK, OTHER
};
protected Type type;
protected String id;
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.id = id;
this.permission = permission;
}
/**
*
*/
public Type type()
{
Type result;
result = this.type;
//
return(result);
}
/**
*
*/
public String id()
{
String result;
result = this.id;
//
return(result);
}
result = this.id;
//
return (result);
}
/**
*
@ -72,25 +56,38 @@ public class AclEntry
public String permission()
{
String result;
result = this.type.toString() + ":" + this.id + ":" + this.permission;
//
return(result);
return (result);
}
/**
*
*/
@Override
public String toString()
{
String result;
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.unix.Unix;
/**
*
*/
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 final public Pattern USER_PATTERN = Pattern.compile("^user:(.*):(.*)$");
@ -26,78 +25,58 @@ public class AclManager
static final public Pattern DEFAULT_MASK_PATTERN = Pattern.compile("^default:mask:(.*):(.*)$");
static final public Pattern DEFAULT_OTHER_PATTERN = Pattern.compile("^default:other:(.*):(.*)$");
/**
*
*
*/
static public void setfacl (String ... args) throws Exception
public static void clearGroup(final String group, final String filePathName) throws Exception
{
try
if ((group == null) || (group.length() == 0) || (filePathName == null) || (filePathName.length() == 0))
{
CmdExec.run(SUDO, "setfacl", args, 1, 5);
throw new Exception("Bad parameters [" + group + "][" + filePathName + "].");
}
catch (Exception exception)
else
{
throw new Exception ("Error running setfacl command for " + StringConcatenator.toStringWithBrackets(args) + ":" + exception.getMessage() + ".");
Unix.setfacl("-R", "-L", "-x", "group:" + group, filePathName);
Unix.setfacl("-R", "-L", "-d", "-x", "group:" + group, filePathName);
}
}
/**
*
*
*/
static public String getAclData (String filePathName) throws Exception
public static void clearId(final String id, 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);
clearUser(id, filePathName);
clearGroup(id, filePathName);
}
/**
*
*
*/
static public String[] getAclEntryLines (String filePathName)
public static void clearUser(final String login, final String filePathName) throws Exception
{
String[] result;
try
if ((login == null) || (login.length() == 0) || (filePathName == null) || (filePathName.length() == 0))
{
result = getAclData(filePathName).split("\n");
throw new Exception("Bad parameters [" + login + "][" + filePathName + "].");
}
catch (Exception exception)
else
{
result = new String[0];
Unix.setfacl("-R", "-L", "-x", "user:" + login, filePathName);
Unix.setfacl("-R", "-L", "-d", "-x", "user:" + login, filePathName);
}
//
return (result);
}
/**
*
*/
static public Acl getAcl (String filePathName) throws Exception
static public Acl getAcl(final String filePathName) throws Exception
{
Acl result;
result = new Acl(filePathName);
String[] entries = getAclEntryLines(filePathName);
// Login pattern: "^[a-z_][a-z0-9_-]*$".
logger.debug("Line=[" + entries[1] + "]");
Matcher matcher = Pattern.compile("^#\\sowner:\\s([a-z_][a-z0-9_-]*)$").matcher(entries[1]);
@ -106,7 +85,7 @@ public class AclManager
logger.debug("group=[" + matcher.group(1) + "]");
result.setOwner(matcher.group(1));
}
// Group pattern: "^[a-z_][a-z0-9_-]*$".
logger.debug("Line=[" + entries[2] + "]");
matcher = Pattern.compile("^#\\sgroup:\\s([a-z_][a-z0-9_-]*)$").matcher(entries[2]);
@ -115,8 +94,7 @@ public class AclManager
logger.debug("group=[" + matcher.group(1) + "]");
result.setOwner(matcher.group(1));
}
for (int nEntry = 3; nEntry < entries.length; nEntry++)
{
String entryLine = entries[nEntry];
@ -131,7 +109,7 @@ public class AclManager
Matcher defaultGroupMatcher = DEFAULT_GROUP_PATTERN.matcher(entryLine);
Matcher defaultMaskMatcher = DEFAULT_MASK_PATTERN.matcher(entryLine);
Matcher defaultOtherMatcher = DEFAULT_OTHER_PATTERN.matcher(entryLine);
AclEntry entry;
if (userMatcher.matches())
{
@ -175,24 +153,118 @@ public class AclManager
}
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() + "]");
}
//
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);
}
/**
*
*/
static public String[] getAclEntryLines(final String filePathName)
{
String[] result;
try
{
result = getAclData(filePathName).split("\n");
}
catch (Exception exception)
{
result = new String[0];
}
//
return (result);
}
/**
*
*/
public static boolean isUsed(AclEntry.Type type, String id, String filePath, String[] filePathNames, int depth) throws Exception
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;
result = false;
boolean ended = false;
int nLine = 0;
@ -217,77 +289,71 @@ public class AclManager
result = false;
}
}
//
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;
if ((type == null) ||
(id == null) || (id.length() == 0) ||
(filePathName == null) || (filePathName.length() == 0) ||
(depth < 0))
result = isUsed(id, filePathName, 0);
//
return (result);
}
/**
*
*/
public static boolean isUsed(final String id, final String filePathName, final int depth) throws Exception
{
boolean result;
if ((id == null) || (id.length() == 0) || (filePathName == null) || (filePathName.length() == 0) || (depth < 0))
{
throw new Exception("Bad parameter: [" + type + "][" + id + "][" + filePathName + "][" + depth + "].");
throw new Exception("Bad parameter: [" + id + "][" + filePathName + "][" + depth + "].");
}
else
{
File file = new File (filePathName);
File file = new File(filePathName);
if (!file.exists())
{
throw new Exception ("File does not exist [" + filePathName + "].");
throw new Exception("File does not exist [" + filePathName + "].");
}
else
{
Acl acl = getAcl(filePathName);
if (acl.contains(type, id))
if (acl.containsId(id))
{
result = true;
}
else if ((file.isDirectory()) && (depth > 0))
{
result = isUsed(type, id, filePathName, file.list(), depth - 1);
result = isUsed(id, file.list(), depth - 1);
}
else
{
result = false;
}
}
}
}
//
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;
result = false;
boolean ended = false;
int nLine = 0;
@ -312,113 +378,25 @@ public class AclManager
result = false;
}
}
//
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);
}
/**
*
*
*/
public static boolean isUsed(String id, String filePathName) throws Exception
static public void setfacl(final String... args) throws Exception
{
boolean result;
result = isUsed(id, filePathName, 0);
//
return (result);
}
/**
*
*/
public static void clearUser(String login, String filePathName) throws Exception
{
if ((login == null) || (login.length() == 0) ||
(filePathName == null) || (filePathName.length() == 0))
try
{
throw new Exception("Bad parameters [" + login + "][" + filePathName + "].");
CmdExec.run(SUDO, "setfacl", args, 1, 5);
}
else
catch (Exception exception)
{
Unix.setfacl("-R", "-L", "-x", "user:" + login, filePathName);
Unix.setfacl("-R", "-L", "-d", "-x", "user:" + login, filePathName);
throw new Exception("Error running setfacl command for " + StringConcatenator.toStringWithBrackets(args) + ":" + exception.getMessage() + ".");
}
}
/**
*
*/
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.Pattern;
@ -11,10 +7,12 @@ import fr.devinsy.util.cmdexec.StreamGobbler;
/**
*
*/
class CmdExecTester {
class CmdExecTester
{
static private org.apache.log4j.Logger logger;
static {
static
{
// Initialize logger.
org.apache.log4j.Logger logger = null;
@ -40,15 +38,17 @@ class CmdExecTester {
/**
*
*/
public static String check(final String title, final StringBuffer source,
final String model) {
public static String check(final String title, final StringBuffer source, final String model)
{
String result;
if (source.indexOf(model) == -1) {
result = String.format("%-40s -> KO <-", title) + "\nGet:\n"
+ source + "\nWaiting:\n" + model;
if (source.indexOf(model) == -1)
{
result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model;
} else {
}
else
{
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!");
Matcher m = Pattern.compile("^#\\sowner:\\s([a-z_][a-z0-9_-]*)$")
.matcher("# owner: cpm");
Matcher m = Pattern.compile("^#\\sowner:\\s([a-z_][a-z0-9_-]*)$").matcher("# owner: cpm");
m.matches();
// System.out.println("owner=[" + m.matches() + "]");
System.out.println("owner=[" + m.groupCount() + "]");
@ -75,19 +75,22 @@ class CmdExecTester {
/**
*
*/
public static void test1() {
try {
public static void test1()
{
try
{
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" };
CmdExec cmd = new CmdExec(command, StreamGobbler.BUFFER,
StreamGobbler.BUFFER);
CmdExec cmd = new CmdExec(command, StreamGobbler.BUFFER, StreamGobbler.BUFFER);
System.out.println("exitVal=[" + cmd.getExitValue() + "]");
System.out.println("out=[" + cmd.getOutStream() + "]");
System.out.println("err=[" + cmd.getErrStream() + "]");
} catch (Exception exception) {
}
catch (Exception exception)
{
exception.printStackTrace();
logger.info("ERRRO=" + exception);
}

View file

@ -1,6 +1,3 @@
import java.io.File;
import org.apache.log4j.BasicConfigurator;
@ -10,7 +7,6 @@ import org.apache.log4j.PatternLayout;
import fr.devinsy.util.FileIterator;
/**
*
*/
@ -19,19 +15,27 @@ public class FileIteratorTester
static private org.apache.log4j.Logger logger;
static
{
{
// Initialize logger.
BasicConfigurator.configure ();
Logger defaultLogger = org.apache.log4j.Logger.getRootLogger ();
defaultLogger.setLevel (org.apache.log4j.Level.DEBUG);
BasicConfigurator.configure();
Logger defaultLogger = org.apache.log4j.Logger.getRootLogger();
defaultLogger.setLevel(org.apache.log4j.Level.DEBUG);
defaultLogger.removeAllAppenders();
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
{
//File f = new File("TestTree/DirectoryOne/titi2");
//File f = new File("/home/cpm/.kde//cache-cpmstar");
// File f = new File("TestTree/DirectoryOne/titi2");
// File f = new File("/home/cpm/.kde//cache-cpmstar");
File f = new File("tests/TestTree/xine.jpg");
System.out.println("exists=" + f.exists());
System.out.println("canonical path = " + f.getCanonicalPath());
@ -57,36 +61,32 @@ public class FileIteratorTester
System.out.println("path = " + f.isFile());
System.out.println("path = " + f.isDirectory());
System.out.println("list = " + f.list());
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("/home/cpm/.kde/cache-cpmstar"), ".*cache.*", false);
//FileIterator i = new FileIterator(new File("tests/TestTree"), ".*dsc.*", 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);
// FileIterator i = new FileIterator(new
// File("/home/cpm/.kde/cache-cpmstar"), ".*cache.*", false);
// FileIterator i = new FileIterator(new File("tests/TestTree"),
// ".*dsc.*", 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())
{
//System.out.println(i.toString());
// System.out.println(i.toString());
System.out.println("File=[" + i.next().getPath() + "]");
}
i.reset();
System.out.println("Cardinal=" + i.finalCountdown());
}
catch(Exception exception)
catch (Exception exception)
{
System.out.println("ERROR:" + exception.getMessage());
}
}
/**
*
*/
public static void main (String[] args)
{
test();
}
}