Child: [r20] (diff)

Download this file

ReadMultipleLine.java    97 lines (80 with data), 2.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* SPDXVersion: SPDX-1.1
*
* Creator: Person: Nuno Brito (nuno.brito@triplecheck.de)
*
* Creator: Organization: TripleCheck (contact@triplecheck.de)
*
* Created: 2013-09-14T00:00:00Z
*
* LicenseName: NOASSERTION
*
* FileName: ReadMultipleLine.java
*
* FileType: SOURCE
*
* FileCopyrightText: <text> Copyright 2013 Nuno Brito, TripleCheck </text>
*
* FileComment: <text> Allows to handle blocks of text separated across
* different lines such as this comment. </text>
*/
package spdxlib;
public class ReadMultipleLine {
public readStatus
status = readStatus.NOTREAD; // indicates if everything was valid or not
public int
lineCount = 0; // how big is this block of text?
public String
output = "";
// non-changing definitions
private final String
textStart = "<text>",
textEnd = "</text>";
public enum readStatus {
NOTREAD, INCOMPLETE, NOSTART, NOEND, INVALID, OK; //; is optional
}
/**
* Gets the full text of sections that are using the <text> and </text> tag
* @param lines The array containing all lines of the file
* @param startLine From where the text block begins
* @return
*/
public void getMultipleLine(String[] lines, int startLine){
// preflight check
if(lines[startLine].contains(textStart) == false){
// no point in continuing, file was not valid
status = readStatus.NOSTART;
return;
}
// get size of whole text file
int numberOfLinesInFile = lines.length;
// go throught each line
for(int i = startLine; i < numberOfLinesInFile; i++){
// always increase the counter
lineCount++;
// get the current line to do some work
String line = lines[i];
//String line = removeLineBreaks(lines[i]);
output += line;
// finish the blow
if(line.contains(textEnd)){
// all done
status = readStatus.OK;
//multipleLine = removeTextTags(line);
break;
}
}
// nothing more to do, just leave
}
/**
* Remove the typical \r\n from text lines
*/
String removeLineBreaks(String input){
String result = "";
// result = input.replace("\r", "");
// result = result.replace("\n", "");
// some weird characters that are not really needed here
result = result.replace("���", " ");
return result;
}
}