41
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
* File-based implementation of the document interface
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
package com.nokia.tracecompiler.document;
|
|
20 |
|
|
21 |
import java.io.File;
|
|
22 |
import java.io.FileInputStream;
|
|
23 |
import java.io.IOException;
|
|
24 |
|
|
25 |
import com.nokia.tracecompiler.file.FileUtils;
|
|
26 |
import com.nokia.tracecompiler.source.SourceConstants;
|
|
27 |
import com.nokia.tracecompiler.source.SourcePropertyProvider;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* File-based implementation of the document interface. This extends the string
|
|
31 |
* document with SourcePropertyProvider implementation which can provide the
|
|
32 |
* file name to TraceCompiler source framework
|
|
33 |
*
|
|
34 |
*/
|
|
35 |
final class FileDocument extends StringDocument implements
|
|
36 |
SourcePropertyProvider {
|
|
37 |
|
|
38 |
/**
|
|
39 |
* The file
|
|
40 |
*/
|
|
41 |
private File file;
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Constructor
|
|
45 |
*
|
|
46 |
* @param file
|
|
47 |
* the document file
|
|
48 |
* @throws IOException
|
|
49 |
* if processing fails
|
|
50 |
*/
|
|
51 |
FileDocument(File file) throws IOException {
|
|
52 |
this.file = file;
|
|
53 |
byte[] buf = new byte[(int) file.length()];
|
|
54 |
FileInputStream fis = new FileInputStream(file);
|
|
55 |
fis.read(buf);
|
|
56 |
fis.close();
|
|
57 |
setSourceData(new String(buf));
|
|
58 |
}
|
|
59 |
|
|
60 |
/*
|
|
61 |
* (non-Javadoc)
|
|
62 |
*
|
|
63 |
* @see com.nokia.tracecompiler.utils.DocumentAdapter#getPropertyProvider()
|
|
64 |
*/
|
|
65 |
@Override
|
|
66 |
public SourcePropertyProvider getPropertyProvider() {
|
|
67 |
return this;
|
|
68 |
}
|
|
69 |
|
|
70 |
/*
|
|
71 |
* (non-Javadoc)
|
|
72 |
*
|
|
73 |
* @see com.nokia.tracecompiler.source.SourcePropertyProvider#getFileName()
|
|
74 |
*/
|
|
75 |
public String getFileName() {
|
|
76 |
return file.getName();
|
|
77 |
}
|
|
78 |
|
|
79 |
/*
|
|
80 |
* (non-Javadoc)
|
|
81 |
*
|
|
82 |
* @see com.nokia.tracecompiler.source.SourcePropertyProvider#getFilePath()
|
|
83 |
*/
|
|
84 |
public String getFilePath() {
|
|
85 |
return FileUtils.convertSeparators(
|
|
86 |
SourceConstants.FORWARD_SLASH_CHAR, file.getParent(), true);
|
|
87 |
}
|
|
88 |
|
|
89 |
}
|